Running out of memory ctfe 16GB

Nierjerson via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 7 13:56:28 PDT 2017


On Thursday, 6 April 2017 at 22:42:28 UTC, ketmar wrote:
> H. S. Teoh wrote:
>
>> On Fri, Apr 07, 2017 at 01:16:20AM +0300, ketmar via 
>> Digitalmars-d wrote:
>>> Dmitry Olshansky wrote:
>>> 
>>>> [...]
>>> or use `char[]` buffer instead, manually increasing it's size 
>>> by some
>>> step.  assigning to such array won't do any copies, so 
>>> growing the
>>> array by 32kb (or even several mb) steps will reduce memory 
>>> footprint
>>> for string builders considerably.
>>
>> Are you sure?  AFAIK, the current CTFE engine will copy values 
>> every
>> time they are assigned, regardless of whether they are 
>> technically
>> "mutable" or not.
>
> i'm sure: i'm using this trick alot. without that, CTFE won't 
> be able to correctly work with arrays at all, 'cause assigning 
> to mutable array element should be visible with all other 
> slices of that array.
>
> sure, CTFE can technically allocate "hidden array object" and 
> re-assign it each time, but it actually has a concept of "owned 
> by CTFE" objects, and if the array was created in CTFE, it 
> becomes owned by CTFE, and copies will be made only on array 
> resize.

How to implement trick is this and are you 100% sure it works?

e.g.,

char[] x;

x.length = 65536;
x.length = 0;

?

If if what you say is correct it should solve my memory problem. 
I do a lot of string appending and memory usage seems to grows 
exponentially.








More information about the Digitalmars-d mailing list