[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: lists with nil play nice for Lua 5.2
- From: David Given <dg@...>
- Date: Fri, 03 Aug 2007 21:47:12 +0100
-----BEGIN PGP SIGNED MESSAGE-----
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?
┌── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ─── 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
-----END PGP SIGNATURE-----