First of all, you've got a memory leak. Every time you draw, you call getArray which allocates a chunk of data using new. That memory is never deleted, and a new chunk is allocated each time. This is going to blow up in your face. Any time you want to do something along the lines of function(foo->getArray()), if foo->getArray() allocates using new and returns the allocated pointer, you will leak. You always, always want to assign to a temporary first, so that you can delete the temporary: temp=foo->getArray(); function(temp); delete[] temp;
Second... ew. Are you sure you want to do a (possibly large) memory allocation plus an iteration of a pointer-based linked list every single time you draw something? Because surely you could figure out a better approach than that? Even if you just implemented it as a std::vector-style dynamically managed array, at least the allocation penalty would be amortized over time if the array was added to, rather than occurring every single frame. And iterating a pointer-based list is just not something you should be doing in every draw call and every frame, if you can possibly avoid it. Drawing is still one of the most highly performance-sensitive parts of the loop, and you really ought to streamline it.
Third, what is wrong with using the rigorously tested standard library? Are you on a platform that has poor/no support for it, or are you just suffering from roll-your-own syndrome?
Show differencesHistory of post edits
#1JTippetts
Posted 10 May 2012 - 07:22 PM
First of all, you've got a memory leak. Every time you draw, you call getArray which allocates a chunk of data using new. That memory is never deleted, and a new chunk is allocated each time. This is going to blow up in your face.
Second... ew. Are you sure you want to do a (possibly large) memory allocation plus an iteration of a pointer-based linked list every single time you draw something? Because surely you could figure out a better approach than that? Even if you just implemented it as a std::vector-style dynamically managed array, at least the allocation penalty would be amortized over time if the array was added to, rather than occurring every single frame. And iterating a pointer-based list is just not something you should be doing in every draw call and every frame, if you can possibly avoid it. Drawing is still one of the most highly performance-sensitive parts of the loop, and you really ought to streamline it.
Third, what is wrong with using the rigorously tested standard library? Are you on a platform that has poor/no support for it, or are you just suffering from roll-your-own syndrome?
Second... ew. Are you sure you want to do a (possibly large) memory allocation plus an iteration of a pointer-based linked list every single time you draw something? Because surely you could figure out a better approach than that? Even if you just implemented it as a std::vector-style dynamically managed array, at least the allocation penalty would be amortized over time if the array was added to, rather than occurring every single frame. And iterating a pointer-based list is just not something you should be doing in every draw call and every frame, if you can possibly avoid it. Drawing is still one of the most highly performance-sensitive parts of the loop, and you really ought to streamline it.
Third, what is wrong with using the rigorously tested standard library? Are you on a platform that has poor/no support for it, or are you just suffering from roll-your-own syndrome?