The app hanging after reach 1750MB of RAM
Stanislav Blinov via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 19 08:57:08 PDT 2017
On Wednesday, 19 April 2017 at 07:28:32 UTC, Suliman wrote:
>> 1. You're measuring it wrong. Array length is already measured
>> in terms of type size.
>
> So should I do:
> cargpspoints.length * cargpspoints[0].sizeof ?
No. .sizeof is the statically known size of a type, it can't take
into account dynamically allocated memory.
cargpspoint.length * cargpspoints[0].sizeof will tell you the
estimate size of the array, in bytes.
But each of the elements also has strings - dynamic arrays that
are allocated elsewhere, their length is not included in that
calculation.
So you could iterate over the array and sum up lengths of all
strings to get an estimate.
Even then, that's just that: an estimate. Actual amount of memory
allocated for a dynamic array T[] *may* be greater than length *
T.sizeof. The only way to know that is to query the allocator
used (in this case, GC).
More information about the Digitalmars-d-learn
mailing list