November 22, 2016
On Sunday, 20 November 2016 at 17:47:50 UTC, MGW wrote:

> ----------------
> core.exception.OutOfMemoryError@src\core\exception.d(693): Memory allocation failed
> ----------------
>
> Simple program and error. Why?  Windows 7 (32) dmd 2.072.0

Making a 100 million bytes array by appending one byte at a time creates a lot of intermediate-size arrays. Ideally these should be garbage collected away but GC in D is not only slow but also leaky. In 32 bits if you have 1000 random int values on the stack or data segment, with uniform distribution, this is 1000 random locations in memory pinned and seen by GC as live, i.e. one per 4 MB of address space. Which means if your array is 4 MB or larger it's almost doomed to be never collected by GC in this scenario. Your program creates a lot of large arrays and they don't get collected because of false pointers and not precise enough GC. Moral of the story: in 32 bits don't allocate anything big (1 MB or more) in GC heap, otherwise there are good chances it will create a memory leak. Use std.container.array  or something similar.
November 22, 2016
On 11/21/16 11:53 AM, ag0aep6g wrote:
> On Monday, 21 November 2016 at 16:37:32 UTC, Kagamin wrote:
>> Anything in .data and .bss sections and stack. See
>> https://issues.dlang.org/show_bug.cgi?id=15723
>
> Ok, not an actual reference then, but a false pointer.

Yes. 100 million bytes is 1/40 of all addressable space on 32-bits. There only needs to be one 4-byte segment somewhere on the stack that points at this, and it won't be collected.

Assuming you have a quite large segment that can't be extended or collected (due to false pointer), this means you have to allocate another large one to satisfy the next allocation (which then could be pinned). And it gets worse from there.

-Steve
November 23, 2016
On Tuesday, 22 November 2016 at 15:53:39 UTC, Steven Schveighoffer wrote:
> On 11/21/16 11:53 AM, ag0aep6g wrote:
Thank you very much for explaining such a difficult and slippery situation.

1 2
Next ›   Last »