The Croc Programming Language
Memblocks

Functions

word_t croc_memblock_new (CrocThread *t, uword_t len)
 
word_t croc_memblock_fromNativeArray (CrocThread *t, const void *arr, uword_t arrLen)
 
word_t croc_memblock_viewNativeArray (CrocThread *t, void *arr, uword_t arrLen)
 
void croc_memblock_reviewNativeArray (CrocThread *t, word_t slot, void *arr, uword_t arrLen)
 
char * croc_memblock_getData (CrocThread *t, word_t slot)
 
char * croc_memblock_getDatan (CrocThread *t, word_t slot, uword_t *len)
 
int croc_memblock_ownData (CrocThread *t, word_t slot)
 

Detailed Description

Functions which operate on memblocks.

Function Documentation

word_t croc_memblock_new ( CrocThread t,
uword_t  len 
)

Creates and pushes a new memblock object that is len bytes long.

Returns
the stack index of the pushed value.
word_t croc_memblock_fromNativeArray ( CrocThread t,
const void *  arr,
uword_t  arrLen 
)

Creates and pushes a new memblock whose data is a copy of the given array.

Parameters
arris the pointer to the array.
arrLenis the length of the array, in bytes.
Returns
the stack index of the pushed value.
word_t croc_memblock_viewNativeArray ( CrocThread t,
void *  arr,
uword_t  arrLen 
)

Creates and pushes a new memblock object that is a view of the given array.

The memblock will not own its data.

Parameters
arris the pointer to the array. It is your responsibility to keep this array around as long as the memblock which views it exists.
arrLenis the length of the array, in bytes.
Returns
the stack index of the pushed value.
void croc_memblock_reviewNativeArray ( CrocThread t,
word_t  slot,
void *  arr,
uword_t  arrLen 
)

Same as croc_memblock_viewNativeArray, except instead of creating a new memblock, it changes an existing memblock at slot so that its data points to the native array.

If the memblock had any data (and owned it), that data will be freed.

Parameters
arris the pointer to the array. It is your responsibility to keep this array around as long as the memblock which views it exists.
arrLenis the length of the array, in bytes.
char* croc_memblock_getData ( CrocThread t,
word_t  slot 
)

Returns a pointer to the data of the memblock in the given slot.

The pointer returned from this may point into Croc's memory (if the memblock owns its data). You are allowed to modify the data at this pointer, but don't store it unless you know the memblock won't be collected!

char* croc_memblock_getDatan ( CrocThread t,
word_t  slot,
uword_t len 
)

Same as croc_memblock_getData, except it also returns the length of the memblock's data in bytes through the len parameter.

The pointer returned from this may point into Croc's memory (if the memblock owns its data). You are allowed to modify the data at this pointer, but don't store it unless you know the memblock won't be collected!

int croc_memblock_ownData ( CrocThread t,
word_t  slot 
)
Returns
nonzero if the memblock at the given slot owns its data (it is allocated on the Croc heap). If this returns 0, it means the memblock is a view of a native array.