3 ms·
This is the correct approach. Let the caller allocate the memory, and if necessary provide a function to calculate the required memory beforehand, and for the c
by layer8 4y ago
This is the correct approach. Let the caller allocate the memory, and if necessary provide a function to calculate the required memory beforehand, and for the caller to specify the size of the memory passed to the primary function. For dynamically-sized results, another option is to provide iteration functions (like when walking a directory tree) in order to simplify memory sizing for each individual function calls.