diff options
Diffstat (limited to 'docs/application/memory.md')
| -rw-r--r-- | docs/application/memory.md | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/docs/application/memory.md b/docs/application/memory.md new file mode 100644 index 0000000..8340141 --- /dev/null +++ b/docs/application/memory.md @@ -0,0 +1,50 @@ +# Memory Pool + +--- + +## Object Definitions + +```c +#define KPL_SLAB_HEADER(STRUCT) struct STRUCT *prev, *next; + +typedef struct _kpl_slab_obj { + KPL_SLAB_HEADER(_kpl_slab_obj); +} kpl_slab_obj; + +typedef struct _kpl_slab { + size_t array_index; + struct _kpl_slab *next; + uint8_t array[]; +} kpl_slab_alloc; + +typedef struct { + uint32_t object_size, array_size; + _Atomic size_t slab_length; + kpl_slab *root; + kpl_slab_obj *pool; + pthread_mutex_t slab_pool_mutex; +} kpl_slab; + +#define KPL_POOL_HEADER(STRUCT) KPL_SLAB_HEADER(STRUCT); uint32_t obj_byte_size + +typedef struct _kpl_pool_obj { + KPL_POOL_HEADER(_kpl_pool_obj); +} kpl_pool_obj; + +typedef strut { + uint32_t min_obj_size; + _Atomic size_t alloc_byte_size; + kpl_pool_obj *root; + pthread_mutex_t root_mutex; +} kpl_pool; +``` + +## Pool Object Size + +The max size of an object in the pool is 2 \*\* 32 + +This allows for 4 aligned bytes after the `POOL_HEADER` macro + +## List Management + +## Tree Management |
