3 ms·
I wrote my own class which created the data (basically an array) once, passed it around, and automatically deleted the data once its parent function returned.
by zandorg 16y ago
I wrote my own class which created the data (basically an array) once, passed it around, and automatically deleted the data once its parent function returned.
I did this by having a reference counter which goes up on a constructor, and down on a destructor, and when it gets to zero and destructs, only then does it delete the data.
This gave me about 10% extra speed in the program as a whole, over using the C++ classes in the STL.
- czhiddy 16y agohttp://en.wikipedia.org/wiki/Reference_counting http://en.wikipedia.org/wiki/Reference_counting ?
- koenigdavidmj 16y agoSounds like the Flyweight design pattern. Basically, if you have a lot of small objects that would take a lot of memory, then you just cache them all. The canonical use case is a word processor that needs one instance of a letter class for each letter in a document. That's a lot of letters, but there is also a lot of repetition. However, if you have several hundred letters `e', all of the same font face and size, then why not just use the same reference to that identical object and save a lot of space? (You improve your program's spatial locality quite a bit as well.)