Advantages of C++11 for Chess?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: Advantages of C++11 for Chess?

Post by Henk »

Multi-threading is even worse than Bit boards. Giving all kinds of annoyance when debugging. Especially when you don't have time.
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: Advantages of C++11 for Chess?

Post by Steve Maughan »

Thanks for all the input. This thread has been more useful than I had hoped.

The string manipulation routines in C++11 look awesome. They are a massive improvement from plain old C.

Thanks - Steve
http://www.chessprogramming.net - Maverick Chess Engine
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Advantages of C++11 for Chess?

Post by lucasart »

Henk wrote:Multi-threading is even worse than Bit boards. Giving all kinds of annoyance when debugging. Especially when you don't have time.
Thank you for adding value to the discussion, once again.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Advantages of C++11 for Chess?

Post by phhnguyen »

Steve Maughan wrote: The string manipulation routines in C++11 look awesome. They are a massive improvement from plain old C.
You have not asked (I guess you may know already) about the main disadvantage of using C++ over plain C ;)

It is a tradeoff about 5-10% of chess speed, according to some old posts and I guess that is still true (it will be great if you can check again via your work).

However it is not really important nowadays since you may gain more from having better codes, using hardware / threads more efficiently.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Advantages of C++11 for Chess?

Post by AlvaroBegue »

phhnguyen wrote:
Steve Maughan wrote: The string manipulation routines in C++11 look awesome. They are a massive improvement from plain old C.
You have not asked (I guess you may know already) about the main disadvantage of using C++ over plain C ;)

It is a tradeoff about 5-10% of chess speed, according to some old posts and I guess that is still true (it will be great if you can check again via your work).
I would need to see a recent test before I believe this. My current estimate of the C++ slowdown is 0%. I am willing to be convinced otherwise, but only by data. :)
User avatar
Look
Posts: 365
Joined: Thu Jun 05, 2014 2:14 pm
Location: Iran
Full name: Mehdi Amini

Re: Advantages of C++11 for Chess?

Post by Look »

Evert wrote:Have you considered C11?

Personally, I use a library called TinyCThread that implements the C11 threads interface on top of whatever native threads you have (Posix or Windows). Seems to work well.

If you want to move to C++, go for it, but if threads are the only reason for doing so, that's probably overkill.
Anyone tried atomic introduced in C11 ?

http://en.cppreference.com/w/c/atomic
Farewell.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Advantages of C++11 for Chess?

Post by Evert »

Look wrote:
Evert wrote:Have you considered C11?

Personally, I use a library called TinyCThread that implements the C11 threads interface on top of whatever native threads you have (Posix or Windows). Seems to work well.

If you want to move to C++, go for it, but if threads are the only reason for doing so, that's probably overkill.
Anyone tried atomic introduced in C11 ?

http://en.cppreference.com/w/c/atomic
I'm using them. Didn't compare to possible alternatives though.
It's a case where operator overloading would have been nice though.
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Advantages of C++11 for Chess?

Post by phhnguyen »

AlvaroBegue wrote: My current estimate of the C++ slowdown is 0%.
No way for similar code because C++ accesses data and functions via class pointers and virtual tables, not directly as plain C.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Advantages of C++11 for Chess?

Post by AlvaroBegue »

phhnguyen wrote:
AlvaroBegue wrote: My current estimate of the C++ slowdown is 0%.
No way for similar code because C++ accesses data and functions via class pointers and virtual tables, not directly as plain C.
That only applies to virtual functions, which you shouldn't be calling in the tight loops of search. Free functions and non-virtual member functions are accessed in C++ the same way functions are accessed in C. You can get the functionality of virtual functions in C using function pointers, and those are also slow.

I don't even know in what sense accessing data is different in C and C++.
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Advantages of C++11 for Chess?

Post by Dann Corbit »

AlvaroBegue wrote:
phhnguyen wrote:
AlvaroBegue wrote: My current estimate of the C++ slowdown is 0%.
No way for similar code because C++ accesses data and functions via class pointers and virtual tables, not directly as plain C.
That only applies to virtual functions, which you shouldn't be calling in the tight loops of search. Free functions and non-virtual member functions are accessed in C++ the same way functions are accessed in C. You can get the functionality of virtual functions in C using function pointers, and those are also slow.

I don't even know in what sense accessing data is different in C and C++.
All of the expensive things (virtual functions, RTTI, try/catch) are used by choice.

If you take a compilable subset of C and compile it with a C++ compiler, it will run the same speed as C code.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.