I'm working with the code in a MFC project that uses CArray class to work with dynamic arrays. It works as such:
CArray<CUSTOM_STRUCT> arr;
while(some_criteria)
{
CUSTOM_STRUCT cs;
add.add(cs);
}
This approach works, but becomes really slow with a large number of additions to dynamic array. So I was curious, is there a way to preallocate memory in CArray before I begin calling the add() method?
There's one caveat though. I can only estimate approximately the resulting number of elements in the array before I go into my while() loop.
PS. I cannot use any other arrays than CArray.
PS2. Due to complexity of this prokect, I would prefer to keep additions to the array via the add() method.