Hey guys, I was working on some particle systems and this was the only way I could figure out to set up the arrays:
if (vertices){
free(vertices);
}
if (textures){
free(textures);
}
vertices = malloc(sizeof(point3D) * 4 * [particles count]);
textures = malloc(sizeof(point2D) * 4 * [particles count]);
The particles constantly change so a new size of array needs to constantly be created at about 60 fps. Is this a bad way of doing things? Could this cause my app to slow down or cause memory thrashing? When I run it under instruments it doesnt look to bad but it is running on the simulator on my mac. Is this ok or is there another way I could be doing this?
**EDIT Ok I went in and rewrote the system it estimates the max amount of particles at creation. Then it uses that to allocate arrays. This system has the trade off that it often overestimates the memory needed by quite a bit but only calls malloc once. I figured it was not that big of a trade of since a maximum realistic overestimate would be like 100 floats, which is not too bad. Thanks for the help guys.