Class NativeMemoryAllocator
- Namespace
- SharpPluginLoader.Core.Memory
- Assembly
- SharpPluginLoader.Core.dll
The default unmanaged memory allocator for SharpPluginLoader.
public class NativeMemoryAllocator : IResizableAllocator, IAllocator
- Inheritance
-
NativeMemoryAllocator
- Implements
- Inherited Members
Properties
Instance
The singleton instance of this allocator.
public static NativeMemoryAllocator Instance { get; }
Property Value
Remarks
Use this any time you need to use NativeMemoryAllocator. Don't create new instances of this class.
Methods
Allocate(nint)
Allocates a block of memory of the specified size.
public void* Allocate(nint size)
Parameters
size
nintThe size of the memory block to allocate.
Returns
- void*
A pointer to the allocated memory block.
Allocate<TObj>(int)
Allocates count
instances of TObj
.
public TObj* Allocate<TObj>(int count = 1) where TObj : unmanaged
Parameters
count
intThe number of instances to allocate.
Returns
- TObj*
A pointer to the allocated memory block.
Type Parameters
TObj
The type of object to allocate.
Free(void*)
Frees a previously allocated memory block.
public void Free(void* ptr)
Parameters
ptr
void*The pointer to the memory block to free.
Reallocate(void*, nint)
Reallocates a previously allocated memory block to the specified size.
public void* Reallocate(void* ptr, nint size)
Parameters
ptr
void*The pointer to the memory block to reallocate.
size
nintThe new size of the memory block.
Returns
- void*
A pointer to the reallocated memory block.
Reallocate<TObj>(TObj*, int)
Reallocates a previously allocated object array to the specified number of instances.
public TObj* Reallocate<TObj>(TObj* ptr, int count) where TObj : unmanaged
Parameters
ptr
TObj*The pointer to the memory block to reallocate.
count
intThe new number of instances to allocate.
Returns
- TObj*
A pointer to the reallocated memory block.
Type Parameters
TObj
The type of object to reallocate.