Memory Rt¶
| Spice | |
|---|---|
Functions¶
sAlloc¶
| Spice | |
|---|---|
Allocates a new block of memory of the given size.
Parameters
| Name | Type | Description |
|---|---|---|
size |
unsigned long |
The size of the block to allocate. |
Returns: Result<heap byte*> — A pointer to the allocated block, or an error if the allocation failed.
sAllocUnsafe¶
| Spice | |
|---|---|
Allocates a new block of memory of the given size. This panics in case of an out of memory situation.
Parameters
| Name | Type | Description |
|---|---|---|
size |
unsigned long |
The size of the block to allocate. |
Returns: heap byte* — A pointer to the allocated block
sRealloc¶
| Spice | |
|---|---|
Reallocates a block of memory to the given size. Subsequently moves the data from the old memory space to the new one.
Parameters
| Name | Type | Description |
|---|---|---|
ptr |
heap byte* |
The pointer to the block to reallocate. |
size |
unsigned long |
The new size of the block. |
Returns: Result<heap byte*> — A pointer to the reallocated block, or an error if the reallocation failed.
sReallocUnsafe¶
| Spice | |
|---|---|
Reallocates a block of memory to the given size. Subsequently moves the data from the old memory space to the new one. This panics in case of invalid input or an out of memory situation.
Parameters
| Name | Type | Description |
|---|---|---|
ptr |
heap byte* |
The pointer to the block to reallocate. |
size |
unsigned long |
The new size of the block. |
Returns: heap byte* — A pointer to the reallocated block, or an error if the reallocation failed.
sCopy¶
| Spice | |
|---|---|
Copies a block of memory to a new block of memory.
Parameters
| Name | Type | Description |
|---|---|---|
oldPtr |
heap byte* |
The pointer to the block to copy. |
newPtr |
heap byte* |
The pointer to the new block to copy to. |
size |
unsigned long |
The size of the block to copy. |
Returns: Result<heap byte*> — A pointer to the copied block, or an error if the copy failed.
sCopyUnsafe¶
| Spice | |
|---|---|
Copies a block of memory to a new block of memory.
Parameters
| Name | Type | Description |
|---|---|---|
oldPtr |
heap byte* |
The pointer to the block to copy. |
newPtr |
heap byte* |
The pointer to the new block to copy to. |
size |
unsigned long |
The size of the block to copy. |
Returns: heap byte* — A pointer to the copied block, or an error if the copy failed.
sMove¶
| Spice | |
|---|---|
Moves the ownership of a heap pointer from oldPtr to the return value. After this operation, oldPtr is set to nil to prevent double frees.
Parameters
| Name | Type | Description |
|---|---|---|
oldPtr |
heap T*& |
The pointer to move ownership from |
Returns: heap T* — The moved pointer
sDestruct¶
| Spice | |
|---|---|
Destroys the given object by calling its dtor if available
Parameters
| Name | Type | Description |
|---|---|---|
obj |
T& |
The object to destroy |
sDealloc¶
| Spice | |
|---|---|
Frees a block of memory. The pointer is zeroed out after freeing the memory to prevent accidental double frees.
Parameters
| Name | Type | Description |
|---|---|---|
ptr |
heap byte*& |
The pointer to the block to free. |
sDelete¶
| Spice | |
|---|---|
Destroys the given heap-allocated instance and frees the memory.
Parameters
| Name | Type | Description |
|---|---|---|
ptr |
heap T*& |
The pointer to the heap-allocated instance |
sYieldOwnership¶
| Spice | |
|---|---|
Yields the ownership of the given heap pointer. After this operation, the original pointer is set to nil to prevent double frees.
Parameters
| Name | Type | Description |
|---|---|---|
ptr |
heap T*& |
The pointer to yield ownership from |
Returns: T* — The yielded pointer
sCompare¶
| Spice | |
|---|---|
Compares the memory behind pointer A and pointer B for equality.
Parameters
| Name | Type | Description |
|---|---|---|
a |
const heap T* |
Pointer A |
b |
const heap T* |
Pointer B |
size |
unsigned long |
Returns: bool — Is memory equal