diff --git a/freelist/freelist.c b/freelist/freelist.c index 7b181ae..35ffa41 100644 --- a/freelist/freelist.c +++ b/freelist/freelist.c @@ -1,7 +1,8 @@ #include "freelist.h" +/* Header block used to keep track of all the free blocks */ 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 */ @@ -9,7 +10,7 @@ static inline size_t align_up_to(size_t n, size_t align) { 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) { if (!ptr) 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; } -// 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) { if (offset == 0) return NULL; // 0 = invalid/null