3 ms·
"That storage location itself must be allocated." Not really, e.g. you can allocate with one allocation both: header + the buffer for the data. When growing, y
by faragon 11y ago
"That storage location itself must be allocated."
Not really, e.g. you can allocate with one allocation both: header + the buffer for the data. When growing, you grow with: size_of_header + elem_size * num_elems (if allocated in the heap).
If you use the stack allocation, you must allocate the maximum size you're going to use, e.g. for pre-allocating room for 100 elements you can do: sv_alloca(sizeof(struct mystruct), 100) or sv_alloca_t(SV_INT32, 100) for built-in type (built-in types for signed/unsigned ingegers allow mixing input types, passing them by value). In the case of stack allocation, if reaching the size limit via "push", you got error in return, but the vector is safe with the last successful operation.