Computer Chess Club Archives


Search

Terms

Messages

Subject: Dynamic memory allocation question

Author: Russell Reagan

Date: 14:34:24 12/02/02


I've never been able to get a clear answer on this. How much time does it take
to allocate memory dynamically, with a call to malloc or new? Are we talking 10
cycles, 100 cycles, 1000 cycles, or more?

I ask because I'm considering playing with some object-oriented ideas, but if
it's 1000 cycles to allocate (say) one move object, I could have completely
generated many (or all) of the moves for the position by the time allocation was
complete, and that's no good. If I could find out this information, I could
potentially save myself a lot of work only to find out my performance went into
the toilet.

I think there are some interesting issues here, such as using a dynamically
growing array (like std::vector) and not having to worry about making sure I'm
not "too deep" or going to cause a stack overflow, or working with different
sub-classes for different move types. If allocation is 100 cycles, clearly
that's no good for allocating a new move object _every_ time you generate a
move, but it may not be so bad when using an std::vector, since it only
allocates occasionally.

Basically, I like the idea of not having to worry about the details of things
like making sure you're within the bounds of an array, and it may be worth a
small performance hit, but I have no idea what the magnitude of the performance
hit is.

Russell



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.