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 4607232
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:40:27+00:00 2026-05-22T00:40:27+00:00

This time, I couldn’t find what I’m looking for (dunno if I’m not searching

  • 0

This time, I couldn’t find what I’m looking for (dunno if I’m not searching for the right stuff…) but, here it is:

In c++, imagine you have a function Bar() that is called once every cycle… like this:

class Foo {
 public:
   void Bar() {
     double my_array[3]; 
     // fills the array based on some calculations
     double my_array1[3]; 
     // fills the array based on some calculations
     double my_array2[3];
     // fills the array based on some calculations
     _member_of_class = my_array + my_array1 + my_array2; //+ overloaded
   }

 private:
   float _member_of_class[3];
}

int main(int argc, char** argv) {
  Foo foo;
  while(/*program running*/) {
    foo.Bar();
    //LOTS of code here
  }
  return 0;
}

Now, my_arrays are temporary arrays, not important to be data members, just used to fill the class member… Obviously, the overhead of calling that function is not necessary… Is there a way (well, I’m trying to avoid putting them as class members) of telling the compiler to “save the allocation space” or something so they is less overhead? const would give any tip to the compiler? I’m not sure I’m being clear…

Anyway, thanks!

  • 1 1 Answer
  • 0 Views
  • 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-22T00:40:28+00:00Added an answer on May 22, 2026 at 12:40 am

    Use a profiler

    As it stands, the function is declared inline in a class. This code will trivially optimize, and the compiler will probably get the allocations out of the loop anyway (depending on how much cruft you have left out of the picture, really).

    Also, the overloaded array operators likely get vectorized in gcc (starting with -O3 of -ftree-vectorize). Just look at the verbose out put with

    g++ -O3 -march-native -ftreevectorizer-verbose=2 ...
    

    to see what loops got vectorized, and if not, why not.
    By all means have a look at the output of g++ -S etc.

    Use a profiler. Don’t ‘optimize’ if you don’t know that it’s necessary.

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

Sidebar

Related Questions

I could do this myself given time but does anyone have a nice asp.net
I've been looking around for some time and couldn't find a clear explanation for
Couldn't find anything about this topic. I have a Windows TCP C++ server application
I'm sorry if this subject has already been answered, but I couldn't find what
first time posting here, Googled for a few hours and I couldn't find anything.
Could somebody please name a few. I could given time, but this is for
Easy question this time. I'm trying to test whether or not a string does
This is similar to my previous posting. But this time I want to call
I have been building enterprise software for the last 10 years. In this time
This time I have problem with virtual fields. I have core class for my

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.