nothings / stb

stb single-file public domain libraries for C/C++
https://twitter.com/nothings
Other
26.31k stars 7.69k forks source link

implemented context forwarding for custom allocators in stbds_arr* functions #1470

Open riri opened 1 year ago

riri commented 1 year ago

Setting a user context with stbds_arrctx() permits custom allocator functions (STBDS_REALLOC() and STBDS_FREE()) to forward that context. The array might be allocated during the call if it was not. Hence it's preferable to reassign the pointer on function return:

my_array = stbds_arrctx(my_array, my_context);

The stbds_arrgrowf() prototype has been modified to pass that context pointer. Hash map functions have been updated to call correctly the allocation function, but context is still not used for those (I'm not using the hash map functions myself, so I preferred to not break them).

The only issue I can see with this implementation is the grow in stbds_array_header structure, not power of 16 sized anymore (possible alignment issue?).