the "new" command

Started by
9 comments, last by hooded_paladin 22 years ago
I fought the whole new/delete thing when I first started with C++. The way I figured out what to do was simply trace through it with a debugger - not a lot can be hidden there.

Speedwise - new and delete are pretty quick. What is not quick is instantiating all of the stuff in your class and running through your constructor. However I am sure they are not faster then add ( about 2 machine cycles??).

I agree with Ataru - if you want to keep it fast avoid constructing / deconstructing objects repeatedly. The best approach would be to allocate a "heap" and use/reuse the same space over and over again. This means you will need to do a little more work on the management of your data but you should see a decent speed improvement. Also - if you do not need to grow or shrink that ''array'' you may be able to keep the memory contiguous for other optimizations.

Good luck



"C and C++ programmers seem to think that the shortest distance between two points is the great circle route on a spherical distortion of Euclidean space."Stephen Dewhurst

This topic is closed to new replies.

Advertisement