|
|
|
|
|
by henesy
1573 days ago
|
|
The first version I implemented did allocate and return the allocated output buffer, but I scrapped that design I never changed the return value after I did this and didn’t see an issue at the time For the record, this program was written casually on a live stream and is hardly a textbook definition of correctness :) |
|
In zig the idiomatic approach (as far as I can tell) is to manage allocator in main/the caller, and passing that down to the callee. Thus allocation strategy (heap/stack/arena etc) is global/caller determined, while resources are "locally" managed.
I generally work in high level languages like ruby, where one rarely worries about the details of (especially string) allocation (beyond trying to not create way too many copies/buffers).
So it's interesting to see what kind of balance on encapsulation/delegation of this concern can/should be found in C.
Thank you for taking the time to comment.