Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: C++ help

Author: Dann Corbit

Date: 16:17:15 06/09/00

Go up one level in this thread


On June 09, 2000 at 19:10:00, Bruce Moreland wrote:
[snip]
>Your question has already been answered, but I'd like to suggest that you
>consider whether you need to use "new" at all.
>
>A lot of people think that heap allocation is a cost-free operation, and it
>isn't.
>
>It's quite often something you have to do, but if you can get away with putting
>the thing on the stack, it's better to do that.

I would like to not only second this, but add a strange anecdote.

I once wrote a sorting program that added strings into a linked list.
I allocated memory for the strings as I read them and added them to the list.
The malloc() profiler time was unbelievable.

I tried a different approach.  I read the whole file first, and then did the
total allocation, and then read the file again.

Reading the file twice was FASTER than individual malloc calls.  I couldn't
believe it.

That was a long time ago (I seem to recall it was under OS/2 but that is not for
sure).  Anyway, malloc() and new can be incredibly costly.



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.