سؤال

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!

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top