The Croc Programming Language
Raw memory management

Functions

void * croc_mem_alloc (CrocThread *t, uword_t size)
 
void croc_mem_resize (CrocThread *t, void **mem, uword_t *memSize, uword_t newSize)
 
void * croc_mem_dup (CrocThread *t, void *mem, uword_t memSize)
 
void croc_mem_free (CrocThread *t, void **mem, uword_t *memSize)
 

Detailed Description

Allocating and freeing arbitrary blocks of memory through a Croc VM.

Function Documentation

void* croc_mem_alloc ( CrocThread t,
uword_t  size 
)

Allocates a block of memory through the Croc memory allocator, using the allocator function that the thread's VM was created with.

This is not garbage-collected; you are entirely responsible for managing this memory. It will, however, be tracked for memory leaks if the library was compiled with the CROC_LEAK_DETECTOR option.

Parameters
sizeis the number of bytes to allocate.
Returns
a pointer to the allocated memory.
void croc_mem_resize ( CrocThread t,
void **  mem,
uword_t memSize,
uword_t  newSize 
)

Resizes a block of memory that was allocated with croc_mem_alloc.

Parameters
[in,out]memis the address of the pointer to the block to resize. This pointer may change as a result of resizing the block.
[in,out]memSizeis the address of the existing size of the memory block. It will be changed to newSize.
newSizeis the new size of the memory block.
void* croc_mem_dup ( CrocThread t,
void *  mem,
uword_t  memSize 
)

Duplicates a block of memory that was allocated with croc_mem_alloc.

The new memory block is the same size and contains the same data.

void croc_mem_free ( CrocThread t,
void **  mem,
uword_t memSize 
)

Frees a block of memory that was allocated with croc_mem_alloc.

You must free every block that you allocated!