lua-users home
lua-l archive

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


On 04.05.2010 11:17, Duncan Cross wrote:
> On Tue, May 4, 2010 at 9:30 AM, François Perrad
> <francois.perrad@gadz.org> wrote:
>> The goal is to improve the performance of most of the object oriented
>> implementations (prototype or class based).
>> The idea is to prevent rehashing during the object instanciation.

[...]

> It sounds like what you want is a Lua interface to the API function
> lua_createtable():
> 
> http://www.lua.org/manual/5.1/manual.html#lua_createtable
> 
> ...which takes a number of array elements and a number of hashed
> elements and preallocates space for them in a newly created table.

The OP wants the table initialized with some known keys/values, so it is
more than the initial size alone.

> It's easy enough to do for yourself, as long as you are in a position
> to actually do stuff with the C API, but I wouldn't mind seeing this
> become a standard Lua function either, as table.create() or
> table.allocate() or something like that. table.proto() could then be
> written as a simple Lua module on top of this.

Let's make a lua module and put it in luarocks, so we can see if it's
needed/popular, and if it shoud be added to the core lua or stay at
luarocks.

IMO, creating tables with preallocated size from lua (table.create())
would be more important than populating it with some data
(table.proto()), because in OO you are creating objects mostly in
initialization phase.

Regards,
miko