DungeonCrawl
Loading...
Searching...
No Matches
memory_management.h
Go to the documentation of this file.
1
5#ifndef MEMORY_MANAGEMENT_H
6#define MEMORY_MANAGEMENT_H
7
8#include <stdlib.h>
9
10#define STANDARD_MEMORY_POOL_SIZE (8 * 1024 * 1024) // 8MB
11#define MIN_MEMORY_POOL_SIZE (1024 * 1024) // 1MB
12#define MIN_MEMORY_BLOCK_SIZE (sizeof(memory_block_t) + 16)// 16 bytes for min user data
13
14typedef struct memory_block_t {
15 size_t size; // size of the block (without the header)
16 int active; // 1 if the block is in use, 0 if it is free
17 struct memory_block_t* next;// pointer to the next block
18 //here lays the user data
20
21typedef struct {
22 size_t pool_size;// size of the memory pool
23 void* memory;
24 memory_block_t* first;// pointer to the first block
26
27
45void* memory_pool_alloc(memory_pool_t* pool, size_t size);
52void memory_pool_free(memory_pool_t* pool, void* ptr);
59
60#endif//MEMORY_MANAGEMENT_H
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 shutdown_memory_pool(memory_pool_t *pool)
Shuts down the memory pool.
void memory_pool_free(memory_pool_t *pool, void *ptr)
Free a memory pool.