lua-users home
lua-l archive

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



> -----Ursprüngliche Nachricht-----
> Von: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] Im
> Auftrag von Krawtschunowski, Wladimir
> Gesendet: Montag, 13. Dezember 2010 09:48
> An: Lua mailing list
> Betreff: AW: Memory needs for table keys
> 
> > The table 'a' will have an array part of length 0, and 'b' will
> > have an array part of length 1 when you say 'b[1]=2'.  From ltable.c:
> >     The actual size of the array is the largest `n' such that at
> >     least half the slots between 0 and n are in use.
> > The array part will therefore stay at length 1 when you say "b[1000]=1".
> >
> > When you say "b[1]=nil" the array part should drop back to length 0,
> > according to that statement, but whether the memory already allocated
> > is freed just yet I don't know.
> Hmm... after the execution of the code the tables a and b have both a
> entry with index 1000 and the value of 1. Why should the array part be 0?
> The largest `n' would be in this case 1000, so the size of the array part
> for both tables would be also 1000 or not?
> i.e. the memory usage of the tables e and f would be different ?
> ---
> e = {10000 = "foo")
> f = {1 = "foo"}

Ok - sorry for the chaos - I understand. If there are not enough elements with numerical keys - they are saved in the hash-part of a table - right? So because a has only one key with value 1000, it is saved in the hash part and no additional memory for the keys 0 until 999 is used.
 --
Wladimir Krawtschunowski
Software developer

Vectron Systems AG
Willy-Brandt-Weg 41
48155 Münster, Germany
Tel.: +49/251/28 56-0

--- 
Vectron Systems AG, Willy-Brandt-Weg 41, 48155 Münster, Germany, Phone +49-251-2856-0, Fax +49-251-2856-560, 
Amtsgericht Münster HRB 10502, Vorstand / Board of Management: Jens Reckendorf, Thomas Stümmler, 
Aufsichtsrat / Supervisory Board: Christian Ehlers (Vorsitz / Chairman)