gd_alloc_funcs(3)

πŸ’– gd_alloc_funcs β€” bestie, let's talk memory managers πŸ’–

okay so you're reading the gd_alloc_funcs(3) page from the GETDATA manual and honestly? this one is lowkey iconic. it's the "hey GetData, pls use my memory allocator instead of the standard one" function. let's get into it 🫢


✨ NAME ✨

gd_alloc_funcs β€” specify an alternate memory manager for GetData's use

like, you're the one picking who hands out the RAM. main character energy fr πŸ’…


🌸 SYNOPSIS 🌸

#include <getdata.h>

void gd_alloc_funcs(void *(*malloc_func)(size_t), void
       (*free_func)(void*));

πŸŽ€ DESCRIPTION πŸŽ€

The gd_alloc_funcs() function is your moment to tell GetData: "bestie, use this memory manager instead" β€” specifically for when it hands you back dynamically allocated data. ✨

So here's the vibe: you pass pointers to two functions that mimic the behaviour of the Standard Library's malloc(3) and free(3). That's it. That's the whole deal.

Passing NULL? That's equivalent to passing a pointer to the corresponding Standard Library function. sooo convenient. which means πŸ‘‰ you can restore the default memory manager by passing all NULLs to this function. reset button, but make it glamorous. πŸ¦‹

Now, which functions actually use your malloc_func to allocate the buffers they return? The list, no skips:

And gd_free_entry_strings(3) will use the free_func you specified to deallocate entry strings. that same function also gets used by GetData to deallocate strings returned by any registered parser callback function (peep gd_cbopen(3) for that tea πŸ‘€).

⚠️ okay important, don't skip this part: Internally, GetData may still allocate buffers on a different heap. So the caller should not assume that any other pointer returned by the library was allocated with the functions specified by this function. And neither should the caller assume that these functions won't be used by GetData library functions to allocate and deallocate temporary buffers. yeah. it's giving "both things can be true". πŸ’€

Changes made to the memory manager are global across GetData. global global. so the caller should only call this function when it is certain that no object allocated with the old memory manager still exists. no cap, this is the dramatic part. πŸ™ˆ

Also? This function always succeeds and returns no value. no error codes, no exit status drama, nothing. it just works. slay. πŸ‘‘


🌈 HISTORY 🌈

The gd_alloc_funcs() function appeared in GetData-0.10.0. a whole era. ⭐


πŸ’œ SEE ALSO πŸ’œ


and that's the page bestie!! πŸ’– this was Version 0.10.1, dated 5 April 2017 β€” so yes, she's a lil vintage, but she ate and left no crumbs. go forth and manage your memory, you absolute legend πŸ§šπŸ’…πŸŒΈ