[DGD] Pathological memory allocation?

Felix A. Croes felix at dworkin.nl
Wed Oct 24 06:51:58 CEST 2018


Dread Quixadhal <quixadhal at gmail.com> wrote:

> I assume that when you do x = x + ({ 1 }), the engine will look for a memory block that's the size of x + 1 elements, and if it doesn't find one, it will allocate a new one and mark the old one as available.
>
> So, if you do a loop where you keep adding elements one-at-a-time, you'll end up using a very large amount of system memory, as there will be lots of N-1 sized chunks sitting around available, but unused.

N-1 sized, and N-2 sized, and...  memory wasted is quadratic.

This is a general problem, it also exists in Java, for example.  As in
Java, in the cloud library I added a StringBuffer class, where small
pieces can repeatedly be added without wasting a lot of memory for
intermediates.

Regards,
Felix Croes



More information about the DGD mailing list