Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Pointers and small data types

  • 03-01-2004 08:04PM
    #1
    Closed Accounts Posts: 423 ✭✭


    Howdee thar
    apart from the obvious (by val, by ref) are there any advantages in passing a small data type, such as an ushort as a reference? Any increases in perf? Just a nuance of a Q....

    Dizz


Comments

  • Registered Users, Registered Users 2 Posts: 79 ✭✭tendofan


    AFAIK, and please correct me if I'm wrong, but if it's something like a simple int then it doesn't make any difference, apart from the obvious value/reference advantages.

    However, if it's a structure, then there may be speed advantages depending on how it's padded internally by
    the compiler.

    Having said that, it's _usually_ more important to get
    your design right than worry about micro-seconds shaved off something by passing by reference.

    Tendofan.


  • Closed Accounts Posts: 392 ✭✭Skyclad


    For a 32 bit system, the pointer size should be 4 bytes, or the same size as an int. A short is 2 bytes, so by passing a pointer to a short, you are in effect passing slightly more data then the actual variable. OTOH, depending on the compiler, there are better speed optimisations for int values (which could apply to pointers too since they take up the same amount of memory). For any larger structures (classes, structs etc) you almost always want to pass them by reference, declaring them as const if you are not going to modify any of their values.

    Dave


  • Closed Accounts Posts: 423 ✭✭Dizz


    For a 32 bit system, the pointer size should be 4 bytes

    Just the answer I needed :)
    Should of really asked the Q - what's the size of a pointer on win32 :rolleyes:

    Cheers
    Dizz


Advertisement