Out of memory error (even when using destroy())

realhet via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 26 02:17:29 PDT 2017


> Jordan Wilson wrote:
> This I think achieves the spirit of your code, but without the 
> memory exception:
>     ubyte[] st;
>     foreach(i; 0..2000){
>         writeln(i);
>         st.length=500_000_000; // auto = new ubyte[500_000_000];
>         st.length=0; // destory(st)
>         st.assumeSafeAppend;
> // prevent allocation by assuming it's ok to overrwrite what's 
> currently in st
>     }

Yea, that's the perfect solution. It uses exactly the amount of 
memory that is required and still I'm using D things only.
The only difference is that I need only one variable outside of 
the loop, but it's well worth it because I only need one large 
buffer at a time.
Also refreshed my knowledge about assumeSafeAppend() which is now 
clear to me, thanks to You.

Using this information I'll be able to do a BigArray class that 
will hold large amount of data without worrying that the program 
uses 3x more memory than needed :D

Thanks for everyone,
Such a helping community you have here!


More information about the Digitalmars-d-learn mailing list