Ejemplo n.º 1
0
        public void Read <T>(long position, out T structure) where T : struct
        {
            IntPtr dest = Marshal.AllocHGlobal(Marshal.SizeOf(default(T)));

            Win32APIs.memcpy(dest, new IntPtr(baseAccessor.ToInt64() + position), (int)Marshal.SizeOf(default(T)));
            structure = (T)Marshal.PtrToStructure(dest, typeof(T));
        }
Ejemplo n.º 2
0
        public void Write <T>(long position, ref T structure) where T : struct
        {
            IntPtr structurePtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));

            Marshal.StructureToPtr(structure, structurePtr, false);
            Win32APIs.memcpy(new IntPtr(baseAccessor.ToInt64() + position), structurePtr, (int)Marshal.SizeOf(default(T)));
            Marshal.FreeHGlobal(structurePtr);
        }