Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: C++ help

Author: James Robertson

Date: 16:27:33 06/09/00

Go up one level in this thread


On June 09, 2000 at 19:10:00, Bruce Moreland wrote:

>On June 09, 2000 at 16:33:25, James Robertson wrote:
>
>>Will my program get sick if I write:
>>
>>int *a = new int[64];
>>int *b = a;
>>....
>>delete [] b;
>>
>>?
>>
>>This question stems from my lack of knowledge about how a program knows how much
>>memory it has allocated at runtime. That is to say, where does the program store
>>the size of a so the memory will be freed if you call delete []? If you try to
>>free this memory from another pointer (b) will it still know that 64 ints need
>>to be deleted?
>>
>>James
>
>Your question has already been answered, but I'd like to suggest that you
>consider whether you need to use "new" at all.

No; putting new in the middle of your Search() function is not a good idea, I
agree. ;)

I intend to use it for something where speed is not crucial and memory can
easily be munched down if I'm not careful.

James

>
>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.
>
>bruce



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.