Reputation: 5616
I have the following simple For Loop in my Open GL ES app :
for (NSValue * value in pointerStorageArray)
{
NSLog(@"Freeing Malloced Data");
free(value);
}
The problem is that the pointerStorageArray contains around 40000 data items (all the data for a 3D object) and therefore the loop takes about a minute to complete.
Is there any way I could speed up the time taken for the loop to complete ?
EDIT
This question is now an illustration of the importance of not coding for 18 hours in a row. Removing the NSLog Statement speeds it up from 5 minutes to 4 seconds ;)
Upvotes: 1
Views: 280
Reputation: 119194
If the slowdown is actually caused by repeated calls to free()
, then you could consider allocating a few larger contiguous blocks of memory, rather than 40000 individual ones.
As always, you should find a way to profile your code to determine exactly where the bottleneck is.
Upvotes: 2