public static LinkedIndexItem <T> FromArray(byte[] bytes) { BinaryReader reader = new BinaryReader(new MemoryStream(bytes)); LinkedIndexItem <T> s = default(LinkedIndexItem <T>); s.Content = ConverterHelper.FromBytes <T>(reader.ReadBytes(SizeHelper.SizeOf(typeof(T)))); s.PreviousItem = reader.ReadInt32(); return(s); }
public static byte[] GetBytes(object str) { int size = SizeHelper.SizeOf(str.GetType()); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); return(arr); }
public static T FromBytes <T>(byte[] arr) where T : struct { T str = new T(); int size = SizeHelper.SizeOf(typeof(T)); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(arr, 0, ptr, size); str = (T)Marshal.PtrToStructure(ptr, str.GetType()); Marshal.FreeHGlobal(ptr); return(str); }
public Index(string path) { _typeSize = SizeHelper.SizeOf(typeof(T)); _stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite); }