public static Pointer AllocateArray(RuntimeTypeHandle handle, uint elementSize, uint elements) { // An array has the following memory layout: // - Pointer TypeDef // - Pointer SyncBlock // - int length // - ElementType[length] elements // - Padding uint allocationSize = ((uint)(Pointer.Size) * 3) + (elements * elementSize); allocationSize = (allocationSize + 3) & ~3u; // Align to 4-bytes boundary var memory = GC.AllocateObject(allocationSize); memory.StorePointer(0, new Pointer(handle.Value)); if (Pointer.Size == 4) { memory.Store32(Pointer.Size, 0); memory.Store32(Pointer.Size * 2, elements); } else { memory.Store64(Pointer.Size, 0); memory.Store64(Pointer.Size * 2, elements); } return(memory); }
public static IntPtr AllocateArray(RuntimeTypeHandle handle, uint elementSize, uint elements) { // An array has the following memory layout: // - IntPtr TypeDef // - IntPtr SyncBlock // - int length // - ElementType[length] elements // - Padding uint allocationSize = ((uint)(IntPtr.Size) * 3) + (elements * elementSize); allocationSize = (allocationSize + 3) & ~3u; // Align to 4-bytes boundary var memory = GC.AllocateObject(allocationSize); Intrinsic.Store(memory, 0, handle.Value); if (IntPtr.Size == 4) { Intrinsic.Store32(memory, IntPtr.Size, 0); Intrinsic.Store32(memory, IntPtr.Size * 2, elements); } else { Intrinsic.Store64(memory, IntPtr.Size, 0); Intrinsic.Store64(memory, IntPtr.Size * 2, elements); } return(memory); }
public static Pointer AllocateObject(Pointer methodTable, uint classSize) { var hashvalue = Interlocked.Increment(ref objectSequence); // An object has the following memory layout: // - Object Header // - Hash Value (32-bit) // - Lock & Status (32-bit) // - MethodTable (Object references point here, so this is relative 0) // - 0 .. n object data fields var allocationSize = 4 + 4 + Pointer.Size + classSize; var memory = GC.AllocateObject((uint)allocationSize); // Hash memory.Store32(0, hashvalue); // Lock & Status memory.Store32(4, 0); // Set MethodTable memory.StorePointer(8, methodTable); return(memory + 8 + Pointer.Size); }
public static Pointer AllocateObject(RuntimeTypeHandle handle, uint classSize) { // An object has the following memory layout: // - Pointer TypeDef // - Pointer SyncBlock // - 0 .. n object data fields var memory = GC.AllocateObject((2 * (uint)(Pointer.Size)) + classSize); memory.StorePointer(0, new Pointer(handle.Value)); if (Pointer.Size == 4) { memory.Store32(Pointer.Size, 0); } else { memory.Store64(Pointer.Size, 0); } return(memory); }
public static IntPtr AllocateObject(RuntimeTypeHandle handle, uint classSize) { // An object has the following memory layout: // - IntPtr TypeDef // - IntPtr SyncBlock // - 0 .. n object data fields var memory = GC.AllocateObject((2 * (uint)(IntPtr.Size)) + classSize); Intrinsic.Store(memory, 0, handle.Value); if (IntPtr.Size == 4) { Intrinsic.Store32(memory, IntPtr.Size, 0); } else { Intrinsic.Store64(memory, IntPtr.Size, 0); } return(memory); }
public static void *AllocateMemory(uint size) { return(GC.AllocateObject(size)); }