Exemplo n.º 1
0
        public static MyNativeMemBuffer AllocNativeMem(int len)
        {
            IntPtr nativeMemBuffer = Marshal.AllocHGlobal(len);

            //clear native mem
            //temp fix
            unsafe
            {
                byte *ptr = (byte *)nativeMemBuffer;
                MyNativeMethods.memset(ptr, 0, len);
            }

            if (nativeMemBuffer != IntPtr.Zero)
            {
                MyNativeMemBuffer buffer = new MyNativeMemBuffer();
                buffer.Ptr        = nativeMemBuffer;
                buffer.Length     = len;
                buffer._buffer_id = System.Threading.Interlocked.Increment(ref s_memId);
                //register this buffer
                lock (s_registerMems)
                {
                    s_registerMems.Add(buffer._buffer_id, buffer);
                }
                return(buffer);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
 public static NodeJsExternalBuffer CreateExternalBuffer(this NapiEnv env, MyNativeMemBuffer memBuffer)
 {
     //we must handle the native buffer properly!!!
     return(env.CreateExternalBuffer(memBuffer.Ptr, memBuffer.Length));
 }