Memory Functions

Summary
Allocate a block of memory.
Change the size of an allocated memory block.
Quickly initialize a portion of a memory block.
Quickly copy the portion of one memory block into another.
Quickly write the contents of a memory block to a node.

alloc

Allocate a block of memory.  This will request a block of memory to be allocated an initialized.  If the request block cannot be allocated, an error will be generated.  The size must be greater than 0 or nothing will be allocated.  The result is a handle to the block of memory which can then be used to access/change/read/write the block.

Params

sizenumber of bytes to allocate

Returns

A memory handle if allocated or 0 if not.

realloc

Change the size of an allocated memory block.  Use this to increase or decrease the size of a memory block while retaining its contents.  Any new bytes added to the end will be initialized to 0, any unused bytes will be discarded.

Params

mhexisting memory block handle
sizenew size in bytes

Returns

A handle to the newly sized memory block (may be different than the memory handle originally provided).

memset

Quickly initialize a portion of a memory block.  Use this to assign a value to every byte in a specified range.  The value will be truncated if larger than a single byte can hold.  The resulting block will have every byte in the specified range set to the given value.

Params

mhmemory handle
offsetwhere in the block to begin writing
valuethe value use in intialization
lenthe number of bytes to initialize

Returns

nothing

memcpy

Quickly copy the portion of one memory block into another.  Use this to copy the bytes of one memory block into another.  The destination must be large enough to contain the specified range of bytes or an error will be generated.

Params

dmhdestination memory handle
doffsetoffset in the destination to begin writing
smhsource memory handle
soffsetoffset in the source to begin reading
lenthe number of bytes to copy

Returns

nothing

send_memory

Quickly write the contents of a memory block to a node.  This will use the memory block as a source of data in performing a write to node operation.

Params

nodenode to write the data to
mhmemory handle to use as the source
offsetoffset in the source memory to begin reading
lennumber of bytes to send to the node

Returns

nothing