Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing Array of objects Composed of other objects as reference to Functions In C++?
    primarykey
    data
    text
    <p>I have a function which calls itself 10 times a second. I am using QTimer for repeat calls. </p> <pre><code>void DisplayClass::UpdateGuiWithData() { //miscellaneous code which is validated SingletonObjectAsThread::instance()-&gt;UpdateFromGuiToExternalHardware(ClassOjbectArray,var1,var2); QTimer::singleShot(100,this,SLOT(UpdateGuiWithData())); } Class A_ComposingClass_B_Object { //boolean and enum variables B ArrayOf_B_Objects[16]; } Class B { //boolean and enum vairables } class DisplayClass { //variables that are not a concern here UpdateGuiWithData(); A ArrayOfObject_A[4]; }; Class SingletonAsThread { //vairables that are not a concern here UpdateFromGui(A_ComposingClass_B_Object*,const bool&amp;,const bool&amp;); }; </code></pre> <p>Here is the deal when I run the code as is, there is a steady increase in memory size but when I comment out the Call to UpdateFromGui call in UpdateGuiWithData class, the memory stays at a constant level of around 51 MB. The UpdateFromGui function has no dynamic memory allocation or GUI functions. It is just a plane jane function that constructs the packet to write to serial port and is called 10 times a second since this is the refresh rate of the hardware.</p> <p><strong>The only reason I could think of the increase in memory is passing the array of objects with each call to UpdateFromGui function. I think with each call we are creating a copy of class objects and hence the increase in memory.</strong> Then I tried to use passing array of objects as reference to the function but couldn't find a suitable declaration for such a function, though I found the definition and usage of such a function. Here is what I found on the net.</p> <p>// Receive Array by reference.</p> <pre><code>void GetArray( int (&amp;Array) [10] ) { } // Test array by reference. void CRabbitDlgDlg::TestArray() { // Pass array by reference. int Array[10] = { 0 }; GetArray( Array ); } </code></pre> <p>My question are </p> <p>--->Am I thinking on the right line or is it something to do with repeated call to singleton</p> <p>class object? </p> <p>--->Also do I need a copy constructor here for Class A, though there is no dynamic </p> <p>allocation or pointer variables in this class? </p> <p>--->What else can be the source of this memory leak (if not its not about copy constructor or singleton calls) which constantly increases the memory usage </p> <p>of the application?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload