On 4/7/17 12:23 AM, H. S. Teoh via Digitalmars-d wrote:
On Fri, Apr 07, 2017 at 01:16:20AM +0300, ketmar via Digitalmars-d wrote:
Dmitry Olshansky wrote:

2) Instead of building out out big string try building each
interface separately. If I'm not mistaken current CTFE will actually
allocate a whole new array on each append and copy things.  Since it
never deallocates building up a huge string by bits and pieces is a
bad idea as it will leak the entire thing on each append.

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.


Yeah, imagine the worst possible way to implement an operation and
you have an idea of what CTFE will actually do.

Copying the whole array on element assignment is not out of question, though I recall there was some work done to prevent it at least in most cases.

----
Dmitry Olshansky

Reply via email to