On 10/26/2026 3:20 PM, Lawrence D’Oliveiro wrote:
> On Mon, 26 Oct 2026 14:53:48 -0700, Chris M. Thomasson wrote: >
>> On 10/26/2026 2:45 PM, Lawrence D’Oliveiro wrote:
>>> >>> On Mon, 26 Oct 2026 13:33:37 -0700, Chris M. Thomasson wrote: >>>
>>>> Say a lib that has foo_create... Well, the damn called must >>>> remember to call foo_destroy, right?
>>> >>> Are you backpedalling from your previous idea that the caller must >>> allocate the memory for the library to use?
>> >> Where did I say must?
> > You said “Managing the memory is the caller’s job in C anyway.” You > didn’t say “could be the caller’s job” as in “the caller could have a > choice”, you said “*is* the caller’s job”. No choice. I.e. the caller > *must* manage memory.
A simple pattern... Now, some libs can do it others are simply not designed that way. foo_alloc_req r = foo_query_alloc(&cfg); void *mem = aligned_alloc(r.align, r.size); /* once */ for (int i = 0; i < n_jobs; ++i) { foo *f = foo_init(mem, r.size, &cfg); /* build in the same block */ /* ... use f ... */ foo_deinit(f); /* object ends, block stays ours */ } free(mem); /* once, at the very end */