Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Passing small structs in C

Name: Anonymous 2013-07-28 13:51

Hi prog. Got a C89 problem.

I want to pass small (less than 64B) structs throught functions that I can't inline because they are used several times elsewhere and are quite big. But it still need it to be very fast.

Should I pass the structs directly (thus copying them) or use a pointer (and getting a dereference penalty) ?

Name: Anonymous 2013-07-28 18:15

Depends on the calling convention. If it fits in a machine word, pass by value, the compiler will optimize it as if you passed in a integer variable. Some calling conventions use between 3-4 CPU registers to pass values to functions. In that case, the struct can be up to 3-4 machine words in size, and the compiler will pack it into the registers for you.

So on 64-bit machines, anything larger than 32 bytes should always be passed by references.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List