mruby/c memory management. More...
Go to the source code of this file.
Data Structures | |
| struct | MEMORY_POOL |
Macros | |
| #define | MRBC_ALLOC_FLI_BIT_WIDTH 9 |
| #define | MRBC_ALLOC_SLI_BIT_WIDTH 3 |
| #define | MRBC_ALLOC_IGNORE_LSBS 4 |
| #define | SIZE_FREE_BLOCKS ((MRBC_ALLOC_FLI_BIT_WIDTH + 1) * (1 << MRBC_ALLOC_SLI_BIT_WIDTH)) |
| #define | MRBC_MIN_MEMORY_BLOCK_SIZE sizeof(FREE_BLOCK) |
| #define | FLI(x) |
| #define | SLI(x) |
| #define | BLOCK_SIZE(p) |
| #define | PHYS_NEXT(p) |
| #define | SET_USED_BLOCK(p) |
| #define | SET_FREE_BLOCK(p) |
| #define | IS_USED_BLOCK(p) |
| #define | IS_FREE_BLOCK(p) |
| #define | SET_PREV_USED(p) |
| #define | SET_PREV_FREE(p) |
| #define | IS_PREV_USED(p) |
| #define | IS_PREV_FREE(p) |
| #define | SET_VM_ID(p, id) |
| #define | GET_VM_ID(p) |
| #define | BPOOL_TOP(memory_pool) |
| #define | BPOOL_END(memory_pool) |
| #define | BLOCK_ADRS(p) |
| #define | MSB_BIT1_FLI 0x8000 |
| #define | MSB_BIT1_SLI 0x80 |
| #define | NLZ_FLI(x) |
| #define | NLZ_SLI(x) |
Typedefs | |
| typedef struct MEMORY_POOL | MEMORY_POOL |
Functions | |
| static int | nlz16 (uint16_t x) |
| static int | nlz8 (uint8_t x) |
| static unsigned int | calc_index (MRBC_ALLOC_MEMSIZE_T alloc_size) |
| static void | add_free_block (MEMORY_POOL *pool, FREE_BLOCK *target) |
| static void | remove_free_block (MEMORY_POOL *pool, FREE_BLOCK *target) |
| static FREE_BLOCK * | split_block (FREE_BLOCK *target, MRBC_ALLOC_MEMSIZE_T size) |
| static void | merge_block (FREE_BLOCK *target, FREE_BLOCK *next) |
| void | mrbc_init_alloc (void *ptr, unsigned int size) |
| void | mrbc_cleanup_alloc (void) |
| void * | mrbc_raw_alloc (unsigned int size) |
| void * | mrbc_raw_alloc_no_free (unsigned int size) |
| void * | mrbc_raw_calloc (unsigned int nmemb, unsigned int size) |
| void | mrbc_raw_free (void *ptr) |
| void * | mrbc_raw_realloc (void *ptr, unsigned int size) |
| unsigned int | mrbc_alloc_usable_size (void *ptr) |
| void | mrbc_alloc_statistics (struct MRBC_ALLOC_STATISTICS *ret) |
Variables | |
| static MEMORY_POOL * | memory_pool |
mruby/c memory management.
Copyright (C) 2015- Kyushu Institute of Technology. Copyright (C) 2015- Shimane IT Open-Innovation Center. This file is distributed under BSD 3-Clause License. Memory management for objects in mruby/c. STRATEGY Using TLSF and FistFit algorithm. MEMORY POOL USAGE (see struct MEMORY_POOL) | Memory pool header | Memory block pool to provide to application | +--------------------+---------------------------------------------+ | size, bitmap, ... | USED_BLOCK, FREE_BLOCK, ..., (SentinelBlock)| MEMORY BLOCK LINK with USED flag and PREV_IN_USE flag in size member's bit 0 and 1. | USED_BLOCK | FREE_BLOCK | USED_BLOCK |... +-----------------+-------------------------------+-----------------+--- |size| (contents) |size|*next|*prev| (empty) |*top|size| (contents) | USED| 1| | 0| | | | | 1| | PREV| 1 | | 1 | | | | | 0 | | Sentinel block at the link tail. ... | USED_BLOCK | ------------------+-----------------+ |size| (contents) | USED| 1| | PREV| ? | | size : block size. *next: linked list, pointer to the next free block of same block size. *prev: linked list, pointer to the previous free block of same block size. *top : pointer to this block's top.
Definition in file alloc.c.
| #define BLOCK_ADRS | ( | p | ) |
| #define BPOOL_END | ( | memory_pool | ) |
| #define BPOOL_TOP | ( | memory_pool | ) |
| #define FLI | ( | x | ) |
| #define IS_FREE_BLOCK | ( | p | ) |
| #define IS_PREV_FREE | ( | p | ) |
| #define NLZ_FLI | ( | x | ) |
| #define NLZ_SLI | ( | x | ) |
| #define PHYS_NEXT | ( | p | ) |
| #define SIZE_FREE_BLOCKS ((MRBC_ALLOC_FLI_BIT_WIDTH + 1) * (1 << MRBC_ALLOC_SLI_BIT_WIDTH)) |
| #define SLI | ( | x | ) |
| typedef struct MEMORY_POOL MEMORY_POOL |
|
static |
|
inlinestatic |
|
inlinestatic |
| void mrbc_alloc_statistics | ( | struct MRBC_ALLOC_STATISTICS * | ret | ) |
| unsigned int mrbc_alloc_usable_size | ( | void * | ptr | ) |
| void mrbc_cleanup_alloc | ( | void | ) |
| void mrbc_init_alloc | ( | void * | ptr, |
| unsigned int | size ) |
| void * mrbc_raw_alloc | ( | unsigned int | size | ) |
| void * mrbc_raw_alloc_no_free | ( | unsigned int | size | ) |
| void * mrbc_raw_calloc | ( | unsigned int | nmemb, |
| unsigned int | size ) |
| void mrbc_raw_free | ( | void * | ptr | ) |
release memory
| ptr | Return value of mrbc_raw_alloc() |
Definition at line 695 of file alloc.c.
| void * mrbc_raw_realloc | ( | void * | ptr, |
| unsigned int | size ) |
re-allocate memory
| ptr | Return value of mrbc_raw_alloc() |
| size | request size |
| NULL | error. |
Definition at line 796 of file alloc.c.
|
inlinestatic |
|
inlinestatic |
|
static |
|
inlinestatic |
|
static |