lua-users home
lua-l archive

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


Nick Trout wrote:


Oops I didn't read you're mail very thoroughly did I? Its true, us men
cannot multitask!

What is the range of these indices? Could you look up the fn in a table?
E.g.

T, TI = {}, {}
COUNT = 1, RANGEMAX = 1000

function setvalue(fn, index, value)
 assert(index>=0 and index<RANGEMAX)
 if not TI[fn] then TI[fn] = RANGEMAX*COUNT; COUNT=COUNT+1 end
 T[TI[fn] + index] = value
End

function getvalue(fn, index)
 assert(index>=0 and index<RANGEMAX)
 return T[TI[fn] + index]
end

i.e. use a look up table to map fns to indice base ranges and add
specific index. If you do it your way you are generating loads of
strings which is inefficient processing wise and in memory use and GC.

Nick

Thanks for the suggestions. The range of indices is likely to be very small, less than 10, as they are function paramater places (1st arg, 2nd arg, etc). A lookup table is reasonable, but I can't for sure limit the range of indices. Perhaps something similar is viable. I'll sleep on it - have a good weekend everyone!

-Lucas