LispBM
Macros | Functions
lbm_memory.h File Reference
#include "lbm_types.h"
#include <stdint.h>
#include <stddef.h>
Include dependency graph for lbm_memory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define LBM_MEMORY_SIZE_64BYTES_TIMES_X(X)   (16*(X))
 
#define LBM_MEMORY_BITMAP_SIZE(X)   (X)
 
#define LBM_MEMORY_SIZE_512   LBM_MEMORY_SIZE_64BYTES_TIMES_X(8)
 
#define LBM_MEMORY_SIZE_1K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(16)
 
#define LBM_MEMORY_SIZE_2K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(32)
 
#define LBM_MEMORY_SIZE_4K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(64)
 
#define LBM_MEMORY_SIZE_8K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(128)
 
#define LBM_MEMORY_SIZE_10K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(160)
 
#define LBM_MEMORY_SIZE_12K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(192)
 
#define LBM_MEMORY_SIZE_14K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(224)
 
#define LBM_MEMORY_SIZE_16K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(256)
 
#define LBM_MEMORY_SIZE_32K   LBM_MEMORY_SIZE_64BYTES_TIMES_X(512)
 
#define LBM_MEMORY_SIZE_1M   LBM_MEMORY_SIZE_64BYTES_TIMES_X(16384)
 
#define LBM_MEMORY_BITMAP_SIZE_512   LBM_MEMORY_BITMAP_SIZE(8)
 
#define LBM_MEMORY_BITMAP_SIZE_1K   LBM_MEMORY_BITMAP_SIZE(16)
 
#define LBM_MEMORY_BITMAP_SIZE_2K   LBM_MEMORY_BITMAP_SIZE(32)
 
#define LBM_MEMORY_BITMAP_SIZE_4K   LBM_MEMORY_BITMAP_SIZE(64)
 
#define LBM_MEMORY_BITMAP_SIZE_8K   LBM_MEMORY_BITMAP_SIZE(128)
 
#define LBM_MEMORY_BITMAP_SIZE_10K   LBM_MEMORY_BITMAP_SIZE(160)
 
#define LBM_MEMORY_BITMAP_SIZE_12K   LBM_MEMORY_BITMAP_SIZE(192)
 
#define LBM_MEMORY_BITMAP_SIZE_14K   LBM_MEMORY_BITMAP_SIZE(224)
 
#define LBM_MEMORY_BITMAP_SIZE_16K   LBM_MEMORY_BITMAP_SIZE(256)
 
#define LBM_MEMORY_BITMAP_SIZE_32K   LBM_MEMORY_BITMAP_SIZE(512)
 
#define LBM_MEMORY_BITMAP_SIZE_1M   LBM_MEMORY_BITMAP_SIZE(16384)
 

Functions

int lbm_memory_init (lbm_uint *data, lbm_uint data_size, lbm_uint *bitmap, lbm_uint bitmap_size)
 
void lbm_memory_set_reserve (lbm_uint num_words)
 
lbm_uint lbm_memory_get_reserve (void)
 
lbm_uint lbm_memory_num_words (void)
 
lbm_uint lbm_memory_num_free (void)
 
lbm_uint lbm_memory_longest_free (void)
 
lbm_uint * lbm_memory_allocate (lbm_uint num_words)
 
int lbm_memory_free (lbm_uint *ptr)
 
void * lbm_malloc (size_t size)
 
void * lbm_malloc_reserve (size_t size)
 
void lbm_free (void *ptr)
 
int lbm_memory_shrink (lbm_uint *ptr, lbm_uint n)
 
int lbm_memory_ptr_inside (lbm_uint *ptr)
 
lbm_int lbm_memory_address_to_ix (lbm_uint *ptr)
 

Function Documentation

◆ lbm_free()

void lbm_free ( void *  ptr)

Free memory allocated with lbm_malloc

Parameters
Pointerto array to free

◆ lbm_malloc()

void* lbm_malloc ( size_t  size)

Malloc like interface to lbm_memory

Parameters
sizeSize in bytes of memory to allocate.
Returns
Pointer to array or NULL.

◆ lbm_malloc_reserve()

void* lbm_malloc_reserve ( size_t  size)

Allocate memory potentially from the reserved memory.

Parameters
sizeSize in bytes of memory to allocate.
Returns
Pointer to array or NULL.

◆ lbm_memory_allocate()

lbm_uint* lbm_memory_allocate ( lbm_uint  num_words)

Allocate a number of words from the symbols and arrays memory.

Parameters
num_wordsNumber of words to allocate.
Returns
pointer to allocated array or NULL.

◆ lbm_memory_free()

int lbm_memory_free ( lbm_uint *  ptr)

Free an allocated array int the symbols and arrays memory.

Parameters
ptrPointer to array to free.
Returns
1 on success and 0 on failure.

◆ lbm_memory_get_reserve()

lbm_uint lbm_memory_get_reserve ( void  )

Get the number of words of memory that is treated as reserve.

Returns
Number of words that are reserved

◆ lbm_memory_init()

int lbm_memory_init ( lbm_uint *  data,
lbm_uint  data_size,
lbm_uint *  bitmap,
lbm_uint  bitmap_size 
)

Initialize the symbols and arrays memory

Parameters
dataPointer to an array of uint32_t for data storage.
data_sizeThe size of the data storage array in number of uint32_t elements.
bitmapPointer to an array of uint32_t for memory allocator meta-data.
bitmap_sizeThe size of the meta-data in number of uint32_t elements.
Returns

◆ lbm_memory_longest_free()

lbm_uint lbm_memory_longest_free ( void  )

Find the length of the longest run of consecutire free indices in the LBM memory.

◆ lbm_memory_num_free()

lbm_uint lbm_memory_num_free ( void  )
Returns
The number of free words in the symbols and arrays memory.

◆ lbm_memory_num_words()

lbm_uint lbm_memory_num_words ( void  )

Size of of the symbols and arrays memory in uint32_t chunks.

Returns
Number of uint32_t words.

◆ lbm_memory_ptr_inside()

int lbm_memory_ptr_inside ( lbm_uint *  ptr)

Check if a pointer points into the lbm_memory

Parameters
ptr
Returns
1 for yes and 0 for no.

◆ lbm_memory_set_reserve()

void lbm_memory_set_reserve ( lbm_uint  num_words)

Set the size of the memory reserve in words.

Parameters
num_wordsNumber of words to treat as reserve.

◆ lbm_memory_shrink()

int lbm_memory_shrink ( lbm_uint *  ptr,
lbm_uint  n 
)

Shrink an allocated array.

Parameters
ptrPointer to array to shrink
nNew smaller size of array
Returns
1 on success and 0 on failure.