Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Pointers and small data types

  • 03-01-2004 7: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