DungeonCrawl
|
Exposes functions for working with the memory management. More...
#include <stdlib.h>
Go to the source code of this file.
Data Structures | |
struct | memory_block_t |
struct | memory_pool_t |
Macros | |
#define | STANDARD_MEMORY_POOL_SIZE (8 * 1024 * 1024) |
#define | MIN_MEMORY_POOL_SIZE (1024 * 1024) |
#define | MIN_MEMORY_BLOCK_SIZE (sizeof(memory_block_t) + 16) |
Typedefs | |
typedef struct memory_block_t | memory_block_t |
Functions | |
memory_pool_t * | init_memory_pool (size_t size) |
Initialize a memory pool of the given size. | |
void * | memory_pool_alloc (memory_pool_t *pool, size_t size) |
Allocate a memory pool. | |
void | memory_pool_free (memory_pool_t *pool, void *ptr) |
Free a memory pool. | |
void | shutdown_memory_pool (memory_pool_t *pool) |
Shuts down the memory pool. |
Exposes functions for working with the memory management.
Definition in file memory_management.h.
#define MIN_MEMORY_BLOCK_SIZE (sizeof(memory_block_t) + 16) |
Definition at line 12 of file memory_management.h.
#define MIN_MEMORY_POOL_SIZE (1024 * 1024) |
Definition at line 11 of file memory_management.h.
#define STANDARD_MEMORY_POOL_SIZE (8 * 1024 * 1024) |
Definition at line 10 of file memory_management.h.
memory_pool_t * init_memory_pool | ( | size_t | size | ) |
Initialize a memory pool of the given size.
This function initializes a memory pool for dynamic memory allocation. If the given size is smaller than the minimum required size, it will be automatically set to the minimum size.
size | The size of the memory pool to initialize. |
size | the size of the memory pool to initialize, when the given size is smaller than 1MB, the size will be automatically set to 1MB |
Definition at line 15 of file memory_management.c.
void * memory_pool_alloc | ( | memory_pool_t * | pool, |
size_t | size ) |
Allocate a memory pool.
pool | The memory pool to allocate. |
size | The size of the memory pool. |
Allocate a memory pool.
If the remaining memory space is lager enough, creates a new unused block for the remaining memory.
pool | the pool to allocate memory from |
size | the size of the memory to allocate |
Definition at line 51 of file memory_management.c.
void memory_pool_free | ( | memory_pool_t * | pool, |
void * | ptr ) |
Free a memory pool.
pool | The pool to free. |
ptr | A pointer to who knows what. |
Free a memory pool.
But first checks if the pointer is contained in the memory pool. If needed it will defragment the memory pool and merge free blocks.
pool | the pool to free memory from |
ptr | the pointer to the memory to free |
Definition at line 94 of file memory_management.c.
void shutdown_memory_pool | ( | memory_pool_t * | pool | ) |
Shuts down the memory pool.
pool | The memory pool to be shut down. |
Definition at line 120 of file memory_management.c.