Thread: Size of function arguments?

  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
    522
    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, 08:28 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Trouble with DMA Segmentation Faults
    By firestorm717 in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 09:20 PM