Re: Usage of memory by arrays

2018-04-05 Thread unDEFER via Digitalmars-d
So, I completely found all answers. In my game of 260 Mb: 100 Mb consumes GC, 100 Mb consumes scene in glNewList. And 30 Mb textures in glTexImage2D. Very well, now I know what to do and how to get it smaller. Big thanks to all.

Re: Usage of memory by arrays

2018-04-05 Thread Jonathan M Davis via Digitalmars-d
On Thursday, April 05, 2018 22:29:54 unDEFER via Digitalmars-d wrote: > On Thursday, 5 April 2018 at 22:06:10 UTC, Jonathan M Davis wrote: > > You could also look at how x.capacity compares to x.length as > > well as core.memory.GC.stats() to see what the GC thinks that > > it's using. On my system

Re: Usage of memory by arrays

2018-04-05 Thread unDEFER via Digitalmars-d
On Thursday, 5 April 2018 at 22:23:12 UTC, Steven Schveighoffer wrote: 1. Compare to C malloc-ing 1.2MB at once (GC uses C malloc underneath) Yes after initialize malloc'ed 1.2Mb in C it consumes 1.6 Mb. 4.8 Mb => 4.9 Mb 2. Have you examined smaller numbers for total? Does it scale linearly

Re: Usage of memory by arrays

2018-04-05 Thread unDEFER via Digitalmars-d
On Thursday, 5 April 2018 at 22:06:10 UTC, Jonathan M Davis wrote: You could also look at how x.capacity compares to x.length as well as core.memory.GC.stats() to see what the GC thinks that it's using. On my system, the x.capacity was only 9 greater than x.length, and GC.stats printed as Ye

Re: Usage of memory by arrays

2018-04-05 Thread Steven Schveighoffer via Digitalmars-d
On 4/5/18 5:44 PM, unDEFER wrote: OK, without reallocation: 8< void main() {     float[3] f;     float[3][] x;     writefln("float = %s bytes", float.sizeof);     writefln("float[3] = %s bytes", f.sizeof);     int before = MemoryUsage();     int to

Re: Usage of memory by arrays

2018-04-05 Thread Jonathan M Davis via Digitalmars-d
On Thursday, April 05, 2018 21:44:35 unDEFER via Digitalmars-d wrote: > OK, without reallocation: > > 8< > void main() > { > float[3] f; > float[3][] x; > writefln("float = %s bytes", float.sizeof); > writefln("float[3] = %s bytes", f.size

Re: Usage of memory by arrays

2018-04-05 Thread Jonathan M Davis via Digitalmars-d
On Thursday, April 05, 2018 21:27:54 unDEFER via Digitalmars-d wrote: > On Thursday, 5 April 2018 at 21:11:53 UTC, Steven Schveighoffer > > wrote: > > But the old block doesn't go away! It's collected and stored in > > a free list for future allocations. > > > > -Steve > > Big thanks, -Steve! Reall

Re: Usage of memory by arrays

2018-04-05 Thread unDEFER via Digitalmars-d
OK, without reallocation: 8< void main() { float[3] f; float[3][] x; writefln("float = %s bytes", float.sizeof); writefln("float[3] = %s bytes", f.sizeof); int before = MemoryUsage(); int total = 100; x = new float[3][total*100

Re: Usage of memory by arrays

2018-04-05 Thread Adam D. Ruppe via Digitalmars-d
On Thursday, 5 April 2018 at 20:58:32 UTC, unDEFER wrote: 100K * float[3] = 2356 Kbytes Why not 1200 Kbytes? My guess is the reallocation triggered by ~= just passed the double threshold there. When the runtime appends, it usually reserves (about) 2x of what it actually needs. This is a pe

Re: Usage of memory by arrays

2018-04-05 Thread unDEFER via Digitalmars-d
On Thursday, 5 April 2018 at 21:11:53 UTC, Steven Schveighoffer wrote: But the old block doesn't go away! It's collected and stored in a free list for future allocations. -Steve Big thanks, -Steve! Really program like the next: ==8<== void main() { float[3] f;

Re: Usage of memory by arrays

2018-04-05 Thread Steven Schveighoffer via Digitalmars-d
On 4/5/18 4:58 PM, unDEFER wrote: It prints: $ ./memory float = 4 bytes float[3] = 12 bytes 100K * float[3] = 2356 Kbytes Why not 1200 Kbytes? Array appending is complex. As you append, it continually "fills in" the memory block you have. But once it outgrows that block, it needs to allocat

Usage of memory by arrays

2018-04-05 Thread unDEFER via Digitalmars-d
Hello! Here very simple test program: --->8 import std.conv; import std.stdio; import std.string; int MemoryUsage() { auto file = File("/proc/self/status"); foreach (line; file.byLine()) { if (line[0..6] == "VmRSS:") { r