Skip to main content
GameDev.net gamedev.net
🔒 Locked

passing structs as arguements

Started by Arenth Apr 28, 2005 at 10:08 PM 1 replies 950+ views
Original Post
Arenth
Arenth
Ok well, I know that passing structs as arguements is slow, and uses up alot of stack space, but what about passing pointers to structs, is there any real speed or memory penalties to passing pointers to structs, I would think not since a pointer is just a 32bit long.
ITGER
ITGER
You can also pass the struct/class by reference. Make it const if it's not being modified, of course.
Kwizatz
Kwizatz
you are correct!

the best way to emulate passing the struct without the stack allocation penalty is:

struct somestruct{int someint;int someotherint;char somechararray[128];};int DoSomething(const somestruct& SomeStruct){printf("%s\n",Somestruct.somechararray);return SomeStruct.someint;}somestruct someStruct;DoSomething(SomeStruct);


You get the drill. [smile]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.