I will be allocating and deallocating MANY dynamic, multidimensional arrays that represent matrices, every frame.
Priorities, even at the expense of error-checking and manual memory management:
- Speed
- Small memory footprint
Are C-style arrays the best choice, given these priorities? I know this is an oft-asked question, but I haven’t been able to find a definitive answer for my circumstance.
If you can characterize the maximum amount of memory needed for a set of these arrays that will be used for any particular ‘frame’ (whatever that is), and if you will be dealing with only a single frame at a time (in other words, you’ll be performing work on a single set of arrays, then dumping all of those arrays before performing another round of work on another set of arrays) then you’ll likely get the best performance by allocating your arrays from a block of static memory that you’ve size appropriate for your largest possible work set.
Then your array allocation can be a simple pool allocator that carves out memory for an array from the front of the block and adjusts the block pointer to just past that allocation to be ready for the next array allocation. When you’re done with the work on that set of arrays, everything can be freed by ‘cleaning the pool’ – simply resetting the block pointer to the start of the static memory pool.
Of course, since you haven’t given much in the way of details for how your work must be done, this technique might not fit at all (that’s probably why you haven’t found a definitive answer yet – such an answer depends on the specific characteristics of the work you’re performing).