Better comments

This commit is contained in:
Imbus 2025-09-09 11:07:46 +02:00
parent dcfd4c01ff
commit c0811e1a95

View file

@ -1,7 +1,8 @@
#include "freelist.h" #include "freelist.h"
/* Header block used to keep track of all the free blocks */
struct __attribute__((packed)) FreeListBlock { struct __attribute__((packed)) FreeListBlock {
uint16_t next_offset; uint16_t next_offset; /* May be 8, 16, 32, 64, whatever */
}; };
/* Align to nearest multiple of align */ /* Align to nearest multiple of align */
@ -9,7 +10,7 @@ static inline size_t align_up_to(size_t n, size_t align) {
return (n + align - 1) & ~(align - 1); return (n + align - 1) & ~(align - 1);
} }
// Convert pointer -> 1-based offset (0 means NULL) /* Convert pointer -> 1-based offset (0 means NULL) */
static inline uint32_t ptr_to_offset(FreeList *fl, void *ptr) { static inline uint32_t ptr_to_offset(FreeList *fl, void *ptr) {
if (!ptr) if (!ptr)
return 0; // NULL maps to 0 return 0; // NULL maps to 0
@ -17,7 +18,7 @@ static inline uint32_t ptr_to_offset(FreeList *fl, void *ptr) {
return (uint32_t)(diff / fl->size) + 1; return (uint32_t)(diff / fl->size) + 1;
} }
// Convert 1-based offset -> pointer (0 means NULL) /* Convert 1-based offset -> pointer (0 means NULL) */
static inline void *offset_to_ptr(FreeList *fl, uint32_t offset) { static inline void *offset_to_ptr(FreeList *fl, uint32_t offset) {
if (offset == 0) if (offset == 0)
return NULL; // 0 = invalid/null return NULL; // 0 = invalid/null