Custom memory allocation functions (malloc, free, calloc, realloc) using a fixed-size static memory pool.
More...
#include <stdlib.h>
#include <stddef.h>
Go to the source code of this file.
|
| void * | malloc (size_t size) |
| | Custom implementation of malloc using a static memory pool.
|
| void | free (void *ptr) |
| | Custom implementation of free for memory allocated by malloc (this custom version).
|
| void * | calloc (size_t count, size_t size) |
| | Custom implementation of calloc using a static memory pool.
|
| void * | realloc (void *ptr, size_t size) |
| | Custom implementation of realloc for memory allocated by malloc (this custom version).
|
Custom memory allocation functions (malloc, free, calloc, realloc) using a fixed-size static memory pool.
This file provides an alternative memory management system for Gama, primarily for environments where dynamic system malloc might be unavailable or undesirable (e.g., embedded systems, WebAssembly with specific memory requirements). It pre-allocates a large static buffer and manages memory chunks within it.
- Warning
- This implementation redefines standard C library functions (malloc, free, calloc, realloc). Care must be taken to ensure this does not conflict with system-level memory allocation or other libraries that expect standard libc behavior. This file is typically included conditionally.
◆ _MALLOC_H
◆ GM_MALLOC
◆ MEMORY
◆ MEMORY_B
◆ MEMORY_SPOTS
◆ MEMORY_TOTAL
◆ calloc()
| void * calloc |
( |
size_t | count, |
|
|
size_t | size ) |
Custom implementation of calloc using a static memory pool.
Allocates a block of memory for an array of count elements, each of size bytes, and initializes all bytes in the allocated block to zero.
- Parameters
-
| count | The number of elements to allocate. |
| size | The size of each element in bytes. |
- Returns
- A pointer to the allocated and zero-initialized memory, or NULL if allocation fails.
◆ free()
Custom implementation of free for memory allocated by malloc (this custom version).
Frees a previously allocated memory block, making it available for future allocations.
- Parameters
-
| ptr | A pointer to the memory block to free. If ptr is NULL, no operation is performed. |
◆ malloc()
| void * malloc |
( |
size_t | size | ) |
|
Custom implementation of malloc using a static memory pool.
Allocates a block of size bytes from the predefined static memory pool.
- Parameters
-
| size | The number of bytes to allocate. |
- Returns
- A pointer to the allocated memory block, or NULL if allocation fails (e.g., out of memory or no suitable spot).
◆ realloc()
| void * realloc |
( |
void * | ptr, |
|
|
size_t | size ) |
Custom implementation of realloc for memory allocated by malloc (this custom version).
Resizes a previously allocated memory block.
- Parameters
-
| ptr | A pointer to the memory block to reallocate. If ptr is NULL, behaves like malloc. |
| size | The new size for the memory block. If size is 0, behaves like free. |
- Returns
- A pointer to the reallocated memory block, or NULL if reallocation fails.