Hello everybody,<div><br></div><div>i&#39;ve been using ginac for some months and is very optimum, </div><div>but recently i&#39;ve been facing a problem with the amount of memory used to store some expressions.</div><div>

i have a linear system of ecuations, with the size of around 8000 elements.</div><div><br></div><div>my first approach on building the matrix was use a map&lt;string, ex*&gt; where each element would correspond to a row element of the matrix.</div>

<div>and all incognints of that row would be inside the expression ex. for a 4x4 system ecuaiton, the storage would be like this</div><div><br></div><div>&lt;&quot;certainKey1&quot;, ex1* &gt; = B1*symbol2 + A1*symbol1 + D1*symbol4</div>

<div>&lt;&quot;certainKey2&quot;, ex2*&gt; = D2*symbol4 + B2*symbol2 + C2*symbol3</div><div><div>&lt;&quot;certainKey3&quot;, ex3* &gt; = B3*symbol2 + A3*symbol1 + D3*symbol4 + C3*symbol3</div><div>&lt;&quot;certainKey4&quot;, ex4*&gt; = A4*symbol1 + B4*symbol2 + C4*symbol3</div>

</div><div><br></div><div>this method was using an acceptable ammount of memory, around 15% of 32GB which was pretty good.</div><div>the bad side of this approach was that when building the Ginac::matrix, i had to sort the elements and search each of them on their corresponding row, additionaly some where hidden because they had coefficient &quot;0&quot;, so i had a list of symbols and on each row i searched for them, in a sorted way using the &quot;coeff&quot; method that Ginac provides.</div>

<div>But i repeat, this was slow.</div><div><br></div><div>The point is that i decided to search for other solution, aiming on reducing the time needed to build the Ginac::Matrix.</div><div>i came with the idea to use map&lt; string, &lt;string, ex&gt; &gt; mapMatrix, which is actually the matrix but sorted automatically because of the strings which are the incognits keyCode.</div>

<div>now building the matrix is almost instant, no search needed, and all elements already sorted.</div><div><br></div><div>however, the program is using all the RAM = 32GB when doing the 8000x8000 problem.</div><div><br>

</div><div>i checked and rechecked for any memory leak, but havent found any so far, </div><div><br></div><div>now the question = why did memory increase so much for just segmenting the expressions into separated smaller ones??</div>

<div>is they same ammount of terms, just in separated sub-expressions., the ex object is too expensive??</div><div><br></div><div><br></div><div><br></div>