lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Roberto Ierusalimschy wrote:
[...]
> This 'n' would increase the memory needed to store each table.
[...]
> That would demand a new test when writing an element to the table (to see
> whether the key is in the array part).
[...]
> Again this demand a test at each writing, to know whether the element
> being written is nil.

This is all correct; but since all this happens in C code inside the VM, the
overhead is trivial. Storing 'n' is just another machine word in the table
structure (and may replace the existing #length field, if there is one).
Comparing for nil is trivial. I would be very surprised if any of this turned
into more than a dozen or so machine instructions. Any extra overhead should
be completely absorbed in general housekeeping.

One possible complication I can see, however, is what happens if the user
creates a table with sparse indices and then fills in the gaps later. Does the
VM move stuff from the hash table portion of the table into the array portion
(your definition!) of the table when this happens, or does the data all end up
in the hash table?

- --
┌── dg@cowlark.com ─── http://www.cowlark.com ───────────────────
│
│ "There does not now, nor will there ever, exist a programming language in
│ which it is the least bit hard to write bad programs." --- Flon's Axiom
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFGs5RQf9E0noFvlzgRAjUjAJ4/FlYxPOwJ7UcxXFFqf017dMqg/wCYwbGq
edNVdOJrkyooX8kc+2+SoA==
=zjju
-----END PGP SIGNATURE-----