Apps     Components     Interfaces     All Files     Source Tree     source: tos.interfaces.MemAlloc.nc

Interface: MemAlloc

Interface for dynamic memory allocators.

Components providing this interface:
tos.lib.TinyAlloc

Components requiring this interface:
tos.lib.TinyDB.AggOperator
tos.lib.TinyDB.DBBufferC
tos.lib.TinyDB.QueryResult
tos.lib.TinyDB.TupleRouterM

Commands

Events

Commands - Details

allocate

result_t allocate(HandlePtr handle, int16_t size)

Allocate a memory region.

Parameters:

handle - Handle to memory region (to be filled in).

size - Size of region in bytes.

Returns: SUCCESS if allocated, FAIL otherwise.

reallocate

result_t reallocate(Handle handle, int16_t size)

Reallocate a region to a new size, copying data over.

Parameters:

handle - Region to resize.

size - New size.

Returns: SUCCESS if reallocated, FAIL otherwise.

lock

result_t lock(Handle handle)

Lock a memory region from being compacted. This is needed if pointers within it are passed around.

Parameters:

handle - Handle to region to lock.

Returns: SUCCESS if locked successfuly, FAIL otherwise.

unlock

result_t unlock(Handle handle)

Unlock a memory region to allow its compaction.

Parameters:

handle - Handle to region to unlock.

Returns: SUCCESS if unlocked successfuly, FAIL otherwise.

free

int16_t free(Handle handle)

Deallocate a memory region and return it to allocatable memory.

Parameters:

handle - Handle to region to free.

Returns: Size of freed region.

compact

result_t compact(void)

Compact the allocated regions to prevent fragmentation.
Returns: Whether the request to compact was accepted.

size

int16_t size(Handle handle)

Get the size of a memory region.

Parameters:

A - memory region.

Returns: The region's size.

isLocked

bool isLocked(Handle handle)

Get whether a region is locked from compaction.

Parameters:

handle - The region to check.

Returns: Whether the region is locked.

freeBytes

uint16_t freeBytes(void)

Return the number of free bytes available in the heap. This is the sum of all free blocks; even after compaction, a single block of this size may not be available if there are locked handles in the heap.
Returns: The number of free bytes.

Events - Details

allocComplete

result_t allocComplete(HandlePtr handle, result_t success)

Signals when an allocation request has completed.

Parameters:

handle - The handle to the requested region.

success - Whether the allocation was successful.

Returns: Should always return SUCCESS.

reallocComplete

result_t reallocComplete(Handle handle, result_t success)

Signals when an reallocation request has completed.

Parameters:

handle - The handle to the requested region.

success - Whether the reallocation was successful.

Returns: Should always return SUCCESS.

compactComplete

result_t compactComplete(void)

Signals when a compaction request has completed.
Returns: Should always return SUCCESS.