Jeff Schwab
10/13/2008 4:45:00 PM
a_linux_user wrote:
> Thanks to all of you who responded. To begin with I am going to look
> into using the standard allocator. Trying to read section 19.4 from
> Stroustrup, but so far haven't figured how to use it. Later I will try
> to post here little pieces of code to get your comments. Thank you
> once again.
That may be an interesting learning exercise, but be forewarned that
standard allocators are not used consistently by different standard
library implementations. They're not anywhere near as useful as they
seem at first, unless you stick with a particular STL implementation.
Furthermore, it is often a waste of time to start optimizing constant
factors before you even have a working program. Since you're working
with graphs, the best places to improve performance (once your program
functions) will probably be in your search and traversal algorithms.
It's hard to optimize without profiling, and it's hard to profile
without working code. Make it right before you worry about making it fast.
My recommendation is to begin with create_node and destroy_node
functions that just use new and delete, and typedef'd pointers that are
either raw (e.g. typedef node* node_pointer; typedef node const*
node_const_pointer;) or reference-counted (e.g. typedef
std::tr1::shared_ptr<node> node_pointer). If you really find that new
and delete are your performance bottleneck down the road, you can always
replace the use of new and delete with something fancier, without
breaking the syntax used in the rest of your program.