Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: many function arguments  (Read 2174 times)

0 Members and 1 Guest are viewing this topic.

eniddelemaj

  • Newbie
  • *
  • Posts: 13
    • View Profile
many function arguments
« 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!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: many function arguments
« Reply #1 on: October 13, 2016, 03:54:52 pm »
How is this related to SFML?
Laurent Gomila - SFML developer

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: many function arguments
« Reply #2 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.
I would like a spanish/latin community...
Problems building for Android? Look here

eniddelemaj

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: many function arguments
« Reply #3 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!:)

 

anything