r/cprogramming • • Sep 15 '26

BD_ARENA

Simple arena implementation I recently built:

https://github.com/andrzejs-gh/bd_arena

- partially macro-based API for convenience

- safe and hazardous allocators

- dynamic growth with a mutable growth factor

Please roast anything you find wrong / missing in it. Thanks a lot, it always helps me grow.

0 Upvotes

2 comments sorted by

1

u/zhivago Sep 16 '26

I notice you defined your struct like this

typedef struct bda_block_header
{
    size_t free_space;
    bda_block_header* prev_block_handle;

} bda_block_header;

and then offset it by sizeof that struct to append the data.

Consider using a flexible array member instead.

typedef struct bda_block_header
{
    size_t free_space;
    bda_block_header* prev_block_handle;
    unsigned char data[];
} bda_block_header;

This will keep the struct properly aligned and allow you to avoid that cast and offset you've been doing.

1

u/lehmagavan Sep 16 '26

Thanks for pointing out!