Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 666527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:49:42+00:00 2026-05-13T23:49:42+00:00

I’m reading some C code like that: double function( int lena,double xa,double ya, double

  • 0

I’m reading some C code like that:

double function( int lena,double xa,double ya, double za, double *acoefs, ...,
                 int lenb,double xb,double yb, double zb, double *bcoefs, ...,
                 same for c,
                 same for d )

This function is called in the code more than 100.000 times so it’s performance-critical.

I’m trying to extend this code but I want to know if it’s efficient or not (and how much this influences the speed) to encapsulate all the parameters in a struct like this

struct PGTO { int len; double x,y,z ; double *acoefs }

and then access the parameters in the function.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T23:49:42+00:00Added an answer on May 13, 2026 at 11:49 pm

    Visual c++ 2008 64 bit seems to pass the structure by having the caller allocate space for a copy of the structure on it’s stack and copying the data items into it and then passing just the address of that copy into the function by value.

    This simple example compiled as follows –

    struct data {
       int a;
       int b;
       int c;
       char d;
       float f;
    };
    
    
    
    
    double f2(data d)
    {
        return d.a+d.b+d.c+d.d+d.f;
    }
    

    Compiles to this –

    movsx   eax, BYTE PTR [rcx+12]
    add eax, DWORD PTR [rcx+8]
    add eax, DWORD PTR [rcx+4]
    add eax, DWORD PTR [rcx]
    movd    xmm0, eax
    cvtdq2ps xmm0, xmm0
    addss   xmm0, DWORD PTR [rcx+16]
    unpcklps xmm0, xmm0
    cvtps2pd xmm0, xmm0
    ret 0
    

    So basically when you pass individual items the caller pushed them onto the stack and the function accesses them relative to the stack. When you pass a strcuture the caller copies the data items into a block of memory on the stack and then passed the address of that into the function, which accesses them relative to that.

    The second way has a couple more assembly languge instructions but that it, so as far as I can tell from my tests there is no significant difference in efficiency between the two methods at all other than a few microseconds. In all my tests the compiler wanted to inline any calls anyway unless I forced it to call it via a pointer so it’s possible that nothing is passed via the stack at all in your real program anyway.

    In my opinion using a struct is clearer and there appear to be no significant differences in speed so go for that one 🙂

    As always, if in doubt over performance you need to profile your exact setup

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.