Giter Club home page Giter Club logo

Comments (6)

DSanchen avatar DSanchen commented on August 10, 2024

Like this: ?

public extern static ssize_t get_name(hid_t attr_id, size_t size, IntPtr name);

   [TestMethod]
   public unsafe void H5Aget_nameTest5()
   {
       size_t buf_size = IntPtr.Zero;
       ssize_t size = IntPtr.Zero;
       hid_t att = H5A.create(m_v2_test_file, "H5Aget_name", H5T.IEEE_F64LE, m_space_scalar);
       Assert.IsTrue(att >= 0);

       // pretend we don't know the size
       size = H5A.get_name(att, buf_size, IntPtr.Zero);
       Assert.IsTrue(size.ToInt32() == 11);
       buf_size = new IntPtr(size.ToInt32() + 1);

       char* namePtr = stackalloc char[(int)buf_size];
       size = H5A.get_name(att, buf_size, (IntPtr)namePtr);
       Assert.IsTrue(size.ToInt32() == 11);
       string name = Marshal.PtrToStringAnsi((IntPtr)namePtr);
       // names should match
       Assert.AreEqual("H5Aget_name", name);
   }

I'm not working with unsafe code so I never came around stackalloc until now. Do you use it for performance reasons ?

from hdf.pinvoke.

hokb avatar hokb commented on August 10, 2024

Exactly. In this particular example we probably could get away with StringBuilder or [MarshalAs] on a plain string (have not tried though). stackallow becomes even more useful if you just need a temporary int[] array for defining dimension lengths or hyperslab parameters a.t.l.
stackalloc also often allows to write code which is free of new statements, which can be of advantage in multithreaded setups to prevent from contention by global locks.

We are currently integrating HDF.PInvoke into ILNumerics.IO.HDF and will add pointer overloads at all places we find useful. However, we do not cover all features of HDF5 yet.

from hdf.pinvoke.

hokb avatar hokb commented on August 10, 2024

Basically, those pointer overloads must simply reflect the HDF5 C API in a 1:1 manner.

from hdf.pinvoke.

gheber avatar gheber commented on August 10, 2024

I'd be fine with that. Let's discuss this at the next pow wow!

from hdf.pinvoke.

gheber avatar gheber commented on August 10, 2024

See issue #72 as a first step. More to come as needed/requested.

from hdf.pinvoke.

hokb avatar hokb commented on August 10, 2024

tested and working fine. (nuget 1.8.17.2, 1.10)

from hdf.pinvoke.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.