lua-users home
lua-l archive

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


In message <a3dk49+ffvn@eGroups.com>, "paulmatthews" writes:
> G'Day,
> 
> I don't know if this has been discussed before. I seached the archive 
> but to no avail. 
> 
> Anyway it appears that lua_pushstring() and lua_pushlstring() take a 
> copy of the string that is passed, which is all fine. However I need 
> to call into lua lots of times, i.e. 100's of millions of times with 
> 30-40 parameters each time, and all those little malloc's and mempy's 
> start to add up.
> 
> Is there anyway to pass strings to lua but tell it. "Hey here's the 
> parameter, but don't bother copying it 'cause I don't want you to 
> change it.

Hmm.  Do you know that lua interns its strings?  What I mean is for any
particular sequence of characters that form a string lua keeps at most
one copy of that sequence in its heap.  So if I go:

lua_pushstring(L, "spong")
lua_pushstring(L, "spong")

there is only one copy of the string "spong" in the heap (there are two
objects both of which reference the same character sequence, but that's
unavoidable in any scheme).

Does that make you any happier?

Cheers,
 drj