3 ms·
I doubt I'd want to use a dynamic array in C without a custom allocator.
by senderista 1y ago
I doubt I'd want to use a dynamic array in C without a custom allocator.
- teo_zero 1y agoYou don't need an explicit allocator: you can create an empty object and vec_push() does the magic of (re)allocating the memory when needed. Instead, what is missing is an automatic deallocator, one that's automatically called when the variable goes out of scope. For example: { vec(int) v={}; /* no extra room allocated */ vec_push(v,1); /* space allocated */ ... use v ... } /* here the space is dellocated, then v is released */ This example doesn't use the same definition of vec as TFA, but something more similar to 'span' by the same author.
- uecker 1y agoAnd you could easily add a version with a custom allocator if you need it.