The app hanging after reach 1750MB of RAM

Stanislav Blinov via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Apr 18 07:09:28 PDT 2017


On Tuesday, 18 April 2017 at 13:28:57 UTC, Suliman wrote:
> Also I can't understand why app take so much memory? I checked 
> array of structures size with this code:
>
> auto mymem = cargpspoints.length * 
> typeof(cargpspoints[0]).sizeof;			
> writeln(mymem);
>
> And it's print: 16963440
> it's about 16MB...
>
> What is takes all other memory?

1. You're measuring it wrong. Array length is already measured in 
terms of type size. But remember that every call result.array 
will allocate, and very call coerce!string will also allocate.
2. Since you're iterating over every result once, there's no 
point in converting it to an array first.
3. Consider using the Row.toStruct() method for conversion.
4. Consider using std.array.appender instead of ~=.

void getSingleTrackInfo()
{

     foreach(item; getTablesGPSSensorList)
     {
         ResultRange result = mysqlconnection.query(sqlquery);

         carGPSPoint cargpspoint; // create struct
         auto arr = appender!(carGPSPoint[]); // create array of 
structures

         foreach(row; result)
         {
             arr ~= row.toStruct(cargpspoint);
         }

         // arr.data should hold the array of structures
     }
}



More information about the Digitalmars-d-learn mailing list