Skip to content

Instantly share code, notes, and snippets.

@theMackabu
Created July 27, 2026 16:34
Show Gist options
  • Select an option

  • Save theMackabu/cc170fc8b5e7095b2ef97eca98c12f8f to your computer and use it in GitHub Desktop.

Select an option

Save theMackabu/cc170fc8b5e7095b2ef97eca98c12f8f to your computer and use it in GitHub Desktop.
static inline size_t max_size_n(const size_t *values, size_t count) {
size_t max = values[0];
for (size_t i = 1; i < count; ++i)
if (values[i] > max) max = values[i];
return max;
}
#define MAX_SIZE(...) \
max_size_n((const size_t[]){__VA_ARGS__}, \
sizeof((const size_t[]){__VA_ARGS__}) / sizeof(size_t)) \
// https://github.com/sharifsegfaults/nalloc/blob/7f023ccbb6f82245ab3a284382e7e018311d7d94/mm.c#L361-L364
size_t expansion_size = ALIGN(MAX_SIZE(
(size_t)(EXPANSION_FACTOR * mem_heapsize()),
sizeof(AllocBlockHeader) + size - recyclable_space,
sizeof(FreeBlockHeader) + sizeof(BlockFooter)
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment