Size of function arguments?

This is a discussion on Size of function arguments? within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, Lets say I have a struct that is would be like 6k in size when its full. I ...

  1. #1
    Drekenzin
    Guest

    Exclamation Size of function arguments?

    Hello everyone,

    Lets say I have a struct that is would be like 6k in size when its full. I need to pass about 1k of the data to a function...

    void sendinfo(struct sixk data);

    --or--

    void sendinfo(int sixk.data1, intsixk.data2);

    Anyway, the question is, would passing just the data I need to send result in a performance increase? Just wanted to check if there was anything I haven't thought about. Thanks.

    -Drekenzin

  2. #2
    Unregistered
    Guest
    sending 6k of data instead of 12k should improve performance on some level, and maybe you might even notice it. But how about passing just four bytes of data to do the same thing? That's the memory cost of sending a pointer! It's also one of the reasons pointers are considered so powerful.

  3. #3
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    Another way would be to declare your function argument as a pointer to the struct type, then you can acess any data item in the struct you need

    void sendinfo(struct sixk *data);

    when you call the function you use the structure concerned as the argument.

    sendinfo(&mystruct);

    now data can acess all elements of mystruct using the -> operator.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  4. #4
    Drekenzin
    Guest
    Ahh, pointers!
    Lol, I completely forgot about pointers =)
    Thanks very much for the advice, will probably speed up my program a lot.

    -Drekenzin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 09:28 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  5. Trouble with DMA Segmentation Faults
    By firestorm717 in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 10:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21