SFML community forums

Help => General => Topic started by: eniddelemaj on October 13, 2016, 03:52:12 pm

Title: many function arguments
Post by: eniddelemaj on October 13, 2016, 03:52:12 pm
is it an advantage when you have more than 5 function arguments?
i  am programming a pong game. i have functions which contains 8 arguments.
and there are several other ones which contains at least more than one.

for me i guess its kind of comfortable just to give arguments for example
the ballshape to update the ball position or something like that.
my worry is that its not very effective and this way of programming can
lead to performance loss am i right?

maybe im wrong but that was my concern.

sorry i didnt think it was necessary to post a code example

thank you for your answears!
Title: Re: many function arguments
Post by: Laurent on October 13, 2016, 03:54:52 pm
How is this related to SFML?
Title: Re: many function arguments
Post by: DarkRoku12 on October 13, 2016, 06:33:29 pm
its depends on the compiler and the processor.

x86 have 4 register: EAX EBX ECX EDX (32 bits registers), a compiler can push directly parameters to the stack.

push [constant]|[register]|[memory adress]
push [constant]|[register]|[memory adress]
call _myFunctionName
 

Often the values pushed are not constant so the compiler needs to use the 4 32-bits registers.
If your function have a lot of arguments the compiler needs to move some data between register.

But if yuro processor supports and your compiler use SIMD extensions you can have 4 more 32-bits register (XMM registers).

If you have 8 arguments better you pack few in structs or something.

But don't worry how many arguments you are passing, it is unprobable that you notice the performance hit if any.

But 8 arguments are kinda ugly in my opinion.


And for those questions go to a general C++ forum.
This forum is to discuss about SFML related things.
Title: Re: many function arguments
Post by: eniddelemaj on October 14, 2016, 06:40:02 pm
How is this related to SFML?

im sorry youre right.it wont happen again.

its depends on the compiler and the processor.

x86 have 4 register: EAX EBX ECX EDX (32 bits registers), a compiler can push directly parameters to the stack.

push [constant]|[register]|[memory adress]
push [constant]|[register]|[memory adress]
call _myFunctionName
 

Often the values pushed are not constant so the compiler needs to use the 4 32-bits registers.
If your function have a lot of arguments the compiler needs to move some data between register.

But if yuro processor supports and your compiler use SIMD extensions you can have 4 more 32-bits register (XMM registers).

If you have 8 arguments better you pack few in structs or something.

But don't worry how many arguments you are passing, it is unprobable that you notice the performance hit if any.

But 8 arguments are kinda ugly in my opinion.


And for those questions go to a general C++ forum.
This forum is to discuss about SFML related things.

okay thank you for your advice!
yes i found it ugly too... thats a good idea with structs i never used it anyway...
thank you for that!:)