Passing a struct by ref

This is a discussion on Passing a struct by ref within the C Programming forums, part of the General Programming Boards category; I have a pretty large and complex struct in my program. I am passing it into multiple functions (or methods), ...

  1. #1
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153

    Passing a struct by ref

    I have a pretty large and complex struct in my program. I am passing it into multiple functions (or methods), which is it in c? Anyways i am wondering if because the struct is so large, i should (or can) pass them by reference with a pointer into the functions. I think some languages do this automatically even if you pass a variable in. I think this will affect the performance which is cpu and disk i/o intensive. Thank you.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    Quote Originally Posted by javaeyes
    Anyways i am wondering if because the struct is so large, i should (or can) pass them by reference with a pointer into the functions.
    Yes, you should.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by javaeyes View Post
    I think this will affect the performance which is cpu and disk i/o intensive. Thank you.
    This is strictly a memory usage issue. Not a disk or CPU issue.


    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    Thanks, laser and quzah.

    -tim

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Firstly, in C they're called "functions".

    Secondly, since passing a large struct by pointer ("reference") will save some CPU cycles that would otherwise be needed to make a copy, it is somewhat of a CPU issue.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  6. #6
    Registered User javaeyes's Avatar
    Join Date
    Feb 2012
    Posts
    153
    thanks ooga

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 05-12-2011, 01:02 AM
  2. Passing struct
    By beginner.c in forum C Programming
    Replies: 4
    Last Post: 04-23-2008, 01:34 AM
  3. passing struct
    By Doxygen in forum C Programming
    Replies: 2
    Last Post: 10-26-2006, 03:05 AM
  4. struct passing
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 09-15-2005, 08:05 AM
  5. passing a struct!
    By OxYgEn-22 in forum C++ Programming
    Replies: 5
    Last Post: 04-29-2002, 12:57 PM

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