ssm
0.0.2
Runtime Library for the Sparse Synchronous Model
|
SSM runtime memory management and allocation. More...
#include <assert.h>
#include <ssm-internal.h>
#include <ssm.h>
#include <stdio.h>
#include <stdlib.h>
Go to the source code of this file.
Data Structures | |
union | block |
(The beginning of) a block of memory. More... | |
struct | mem_pool |
A memory pool, which maintains a free list. More... | |
Macros | |
#define | BLOCKS_PER_PAGE (SSM_MEM_PAGE_SIZE / sizeof(block_t)) |
The number of blocks in each memory page. More... | |
#define | UNINITIALIZED_FREE_BLOCK ((block_t *)0x0) |
A "pointer" that points to the next contiguous block in memory. More... | |
#define | END_OF_FREELIST ((block_t *)0x42) |
Sentinel value indicating the end of the free list. More... | |
Typedefs | |
typedef union block | block_t |
(The beginning of) a block of memory. More... | |
Functions | |
static size_t | find_pool_size (size_t size) |
Find the memory pool for some arbitrary size. More... | |
static block_t * | find_next_block (block_t *block, size_t pool_size) |
void | ssm_mem_init (void *(*alloc_page_handler)(void), void *(*alloc_mem_handler)(size_t), void(*free_mem_handler)(void *, size_t)) |
Initializes the underlying allocator system. More... | |
void | ssm_mem_destroy (void(*free_page_handler)(void *)) |
Tears down the underlying allocator system. More... | |
void * | ssm_mem_alloc (size_t size) |
Allocate a contiguous range of memory. More... | |
void | ssm_mem_free (void *m, size_t size) |
Deallocate memory allocated by ssm_mem_alloc(). More... | |
ssm_value_t | ssm_new_time_int (ssm_time_t time) |
Allocate a ssm_time on the heap. More... | |
ssm_value_t | ssm_new_adt_int (uint8_t field_count, uint8_t tag) |
Allocate a new ADT object on the heap. More... | |
ssm_value_t | ssm_new_sv_int (ssm_value_t val) |
Allocate an ssm_sv on the heap. More... | |
ssm_value_t | ssm_new_closure_int (ssm_func_t f, uint8_t arg_cap) |
Allocate a closure on the heap. More... | |
ssm_value_t | ssm_new_array_int (uint16_t elems) |
Allocate an array on the heap. More... | |
ssm_value_t | ssm_new_blob_int (uint16_t size) |
Allocate a blob on the heap. More... | |
void | ssm_drop_final (ssm_value_t v) |
Finalize and free a heap object. More... | |
void | ssm_dups (size_t cnt, ssm_value_t *arr) |
Call ssm_dup() on an array of values. More... | |
void | ssm_drops (size_t cnt, ssm_value_t *arr) |
Call ssm_drop() on an array of values. More... | |
void | ssm_mem_statistics_collect (ssm_mem_statistics_t *stats) |
Collect and return statistics about the heap. More... | |
Variables | |
struct mem_pool | mem_pools [SSM_MEM_POOL_COUNT] |
Memory pools from SSM_MEM_POOL_MIN to SSM_MEM_POOL_MAX. More... | |
static void *(* | alloc_page )(void) |
Page allocation handler, set by ssm_mem_init(). More... | |
static void *(* | alloc_mem )(size_t size) |
Large memory allocation handler, set by ssm_mem_init(). More... | |
static void(* | free_mem )(void *mem, size_t size) |
Large memory release handler, set by ssm_mem_init(). More... | |
static size_t | num_pages_allocated = 0 |
Tracks how many pages have been allocated by alloc_pool(). More... | |
static size_t | live_objects = 0 |
static size_t | pages_allocated [SSM_MEM_POOL_COUNT] = {0} |
static size_t | objects_allocated = 0 |
static size_t | objects_freed = 0 |
SSM runtime memory management and allocation.
Definition in file ssm-mem.c.
#define BLOCKS_PER_PAGE (SSM_MEM_PAGE_SIZE / sizeof(block_t)) |
#define UNINITIALIZED_FREE_BLOCK ((block_t *)0x0) |
#define END_OF_FREELIST ((block_t *)0x42) |
(The beginning of) a block of memory.
The size of each block varies depending on which memory pool it resides in. When a block is being used (allocated), block_buf effectively gives a pointer to the beginning that block that can be indexed into.
When a block is not being used, it is maintained in a free list. If it is not at the head of the free list, then it is pointed to by the free_list_next field of some other block_t, while its own free_list_next points to the next block in the free list. To avoid initializing the free_list_next fields of "fresh" blocks, when free_list_next is UNINITIALIZED_FREE_BLOCK, the next free block contiguously follows the current block in memory. The last free block points to END_OF_FREELIST.
|
inlinestatic |
Find the memory pool for some arbitrary size.
Tries to find the smallest memory pool that will fit a block of size. Returns SSM_MEM_POOL_COUNT if no such pool exists, i.e., if size is greater than SSM_MEM_POOL_MAX.
Since SSM_MEM_POOL_COUNT is a (small) compile-time constant, this linear search is effectively contant time.
size | the block size whose memory pool we are looking for. |
struct mem_pool mem_pools[SSM_MEM_POOL_COUNT] |
Memory pools from SSM_MEM_POOL_MIN to SSM_MEM_POOL_MAX.
|
static |
Page allocation handler, set by ssm_mem_init().
|
static |
Large memory allocation handler, set by ssm_mem_init().
|
static |
Large memory release handler, set by ssm_mem_init().
|
static |
|
static |