std::vector<> considered harmful

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: std::vector<> considered harmful

Post by Henk »

vittyvirus wrote:
Henk wrote:
lucasart wrote:
Henk wrote:
lucasart wrote:
syzygy wrote:
flok wrote:I wonder if any of you has suggestions for improving it any further.
Do not allocate any objects at all within your search.
Exactly!

A well written chess engine should not do any dynamic memory allocation, apart from the obvious hash table(s).

If you need to dynamically allocate/resize anything, you're doing it all wrong. Instead of wondering whether to choose std::vector vs. pointer+realloc, ask yourslef what you are doing wrong and redesign your code.
I am currently using movelists but also iterator objects and move handlers one for captures, one for killers etc. All dynamically allocated. Lots of work to do.

If I am going to reuse movelists of a pre-allocated pool it might be that clearing them will be expensive too. But of course instead of allocating power(N, BF) movelists I only need to allocate N such lists but they still have to be cleared power(N, ..) times.
I said well written engine. Obviously that excludes any work from: you, Folkert, Syed, etc.
Ok that's a good reason for me to quit.
Depends on what Lucas means by a 'well written engine'. He wrote a 2800 and now thinks himself god.
Lucas has always right. He tried to save me from this misery before one year ago when he called me a troll and tried to chase me away. I should have listened to my best friend.
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: std::vector<> considered harmful

Post by ZirconiumX »

I had previously tried to keep my mouth shut when Lucas said something like this. I have, frankly, had enough.

It is my personal opinion that what Lucas has just said violates charter point #3.
talkchess wrote: Once a member gains access to the message board, he may read all messages and post new or response messages with the proviso that these new or response messages:
...
3. Do not contain personal and/or libelous attacks on others
He is quite clearly, albeit indirectly, attacking Syed, Folkert and Henk. This is not acceptable.

I have already left this forum once over people making stupid insults like this.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: std::vector<> considered harmful

Post by lucasart »

ZirconiumX wrote: He is quite clearly, albeit indirectly, attacking Syed, Folkert and Henk. This is not acceptable.
I'm saying that their engines are poorly designed. But, at least, they've written one.
ZirconiumX wrote: I have already left this forum once over people making stupid insults like this.
And yet, here you are...
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: std::vector<> considered harmful

Post by Henk »

I am not using my IChessPieceVisitorFactory interface class anymore.
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: std::vector<> considered harmful

Post by ZirconiumX »

lucasart wrote:
ZirconiumX wrote: He is quite clearly, albeit indirectly, attacking Syed, Folkert and Henk. This is not acceptable.
I'm saying that their engines are poorly designed. But, at least, they've written one.
That was cold.

Considering you've given up DiscoCheck due to recognising your own code is poorly designed, I'm not sure you're in a position to tell people things like that.

If Marco, or Fabien said something like that, then yes, I would probably agree with them, due to the fact that they posess the unique ability to be polite.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: std::vector<> considered harmful

Post by vittyvirus »

ZirconiumX wrote:
lucasart wrote:
ZirconiumX wrote: He is quite clearly, albeit indirectly, attacking Syed, Folkert and Henk. This is not acceptable.
I'm saying that their engines are poorly designed. But, at least, they've written one.
That was cold.

Considering you've given up DiscoCheck due to recognising your own code is poorly designed, I'm not sure you're in a position to tell people things like that.

If Marco, or Fabien said something like that, then yes, I would probably agree with them, due to the fact that they posess the unique ability to be polite.

Matthew:out
+1
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: std::vector<> considered harmful

Post by elcabesa »

I used to use std::vector<> for a lot of things inside my engine. I realized in early development that std::vector is not suitable for storing list of generated moves because it's too slow.
I used it to store past moves information ( undo moves information) but the i realized that when the size growth and it needs to be reallocated ALL THE REFERENCE to the data are invalidated.

at this point I switched back to fixed size array
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: std::vector<> considered harmful

Post by AlvaroBegue »

elcabesa wrote:[...]
I used it to store past moves information ( undo moves information) but the i realized that when the size growth and it needs to be reallocated ALL THE REFERENCE to the data are invalidated.
You can easily get around that by using indices instead of references or pointers.
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: std::vector<> considered harmful

Post by elcabesa »

yes but saving a reference should be faster than every time you need an information access the data by indices.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: std::vector<> considered harmful

Post by AlvaroBegue »

elcabesa wrote:yes but saving a reference should be faster than every time you need an information access the data by indices.
Do you say that because you have measured it or because of some intuition? Don't trust your intuitions: The processor has addressing modes that make this kind of access really fast, at least if the element size is a small power of two.