lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2014/1/2 Enrico Colombini <erix@erix.it>:
> ---------------------------------
>
> Lua 5.2 prints:
>
> initial state: 15.0 KB
> allocated a large string: 991.6 KB
> assigned the same string: 991.6 KB
> allocated another, different, large string: 1968.2 KB
> constructed a large string identical to an existing string: 1968.2 KB
> deleted all strings: 15.0 KB
>
> ---------------------------------
>
> As you can see, in both cases a string built by concatenation does not take
> up extra memory if it is identical to an existing one. Change the final 'x'
> of the s4 expression to an 'y' (also comment out the assert) and you will
> see the difference.

Are you sure you ran the test using Lua 5.2? I did and here are my results:

initial state: 24.2 KB
allocated a large string: 1000.7 KB
assigned the same string: 1000.7 KB
allocated another, different, large string: 1977.3 KB
constructed a large string identical to an existing string: 2953.9 KB
deleted all strings: 24.1 KB

As expected by the change in 5.2, the re-creation of a string
identical to an existing one increase memory usage by one megabyte,
contrary to your results.

FWIW I'm using "Lua 5.2.3  Copyright (C) 1994-2013 Lua.org, PUC-Rio",
slightly patched, on Windows x64.