diff options
| author | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-27 10:31:39 +0100 |
|---|---|---|
| committer | Thomas Vanbesien <tvanbesi@proton.me> | 2026-02-27 10:31:39 +0100 |
| commit | 7de95ddd662b52c803d307b6028fd90a1aa71892 (patch) | |
| tree | 2bd2a03b20dfe5510cdb74c5b362e6b7f5d9dd13 /inc | |
| parent | 29b8c1556bf456596c6c067d413b65b51e17724e (diff) | |
| download | malloc-7de95ddd662b52c803d307b6028fd90a1aa71892.tar.gz malloc-7de95ddd662b52c803d307b6028fd90a1aa71892.zip | |
Add zone allocation, internal data structures, and README
Implement mmap-based zone allocation for TINY (<=128B) and SMALL
(<=1024B) categories. malloc now creates zones on demand and
returns a pointer to the first chunk.
Diffstat (limited to 'inc')
| -rw-r--r-- | inc/malloc_internal.h | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/inc/malloc_internal.h b/inc/malloc_internal.h new file mode 100644 index 0000000..fe275e3 --- /dev/null +++ b/inc/malloc_internal.h @@ -0,0 +1,45 @@ +/** + * @file malloc_internal.h + * @brief Internal data structures and macros for the ft_malloc allocator. + */ + +#ifndef MALLOC_INTERNAL_H +#define MALLOC_INTERNAL_H + +#include <stddef.h> + +#define TINY_MAX 128 +#define SMALL_MAX 1024 +#define ALIGNMENT 16 +/* Round x up to the nearest multiple of ALIGNMENT. */ +#define ALIGN(x) (((x) + (ALIGNMENT - 1)) & ~(ALIGNMENT - 1)) +#define MIN_ALLOC_COUNT 100 + +/* Header embedded before each allocation block inside a zone. */ +typedef struct s_chunk +{ + size_t size; + struct s_chunk *next; + int is_free; +} t_chunk; + +/* Header at the start of each mmap'd region. */ +typedef struct s_zone +{ + struct s_zone *next; + size_t size; +} t_zone; + +/* Global state: one linked list per zone category. */ +typedef struct s_heap +{ + t_zone *tiny; + t_zone *small; + t_zone *large; +} t_heap; + +extern t_heap g_heap; + +t_zone *zone_new (size_t alloc_max); + +#endif |
