2 ms·
You 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 m
by teo_zero 1y ago
You 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.