Moderator: Andres Valverde
YvesLejeail wrote:Hi !
it is said everywhere on the web that passing byref is much more efficient than passing byval. But sometimes the contrary is also said... As far as I remember there are some cases which can lead to "overhead", when you pass something byref, then passing in another sub byref, then passing in another byref,...So I suppose it depends of the programme.
YvesLejeail wrote:Hello all,
My chess engine is very weak, so I have lot of work to improve it. But very often when I try to ameliorate the code, there is a huge nps drop (a factor 3 to 10 often). My question is why ? Could someone explain me so that I could stop doing silly changes in the code, cause it's time consuming and very desperating ?
It is very uneasy for me to describe exactly when it arise, otherwise I would not post here. Although, is it possible to have something to do with passing tables byref or byval through subroutines ? I use tables in move generation (move_from, move_to, move_expected_score by SEE) and sorting, recently I tried to change something in the argument of quiescent move generation subroutine, and the nps droped : the code seems to prefer passing Byval instead that Byref as I have noticed (at least I suppose). Could it be due to the VB.net, and why? I know lot of you are using C or C++ but the problem should be common to these languages (I still suppose). Could it be a stack limitation or something like that (sorry to ask things I don't really understand) Is the code structure very important ? Is it better to avoid passing tables through subroutines ?
I'm not a guru programmer, being sure of nothing, so, any idea is welcomed . Thanks for any help,
Yves
Dann Corbit wrote:Passing objects by reference has an evil side effect: Modifying them in the called function also modifies them in the caller.
So it means you must be very careful about what you are doing.
A change from call by value to call by reference is very drastic. You shoul do that only if it is absolutely necessary.
Alessandro Scotti wrote:Dann Corbit wrote:Passing objects by reference has an evil side effect: Modifying them in the called function also modifies them in the caller.
So it means you must be very careful about what you are doing.
A change from call by value to call by reference is very drastic. You shoul do that only if it is absolutely necessary.
In this case it really helps, if the language supports it, to declare references and pointers as "const", so the compiler won't let you modify them by mistake.
Return to Programming and Technical Discussions
Users browsing this forum: No registered users and 20 guests