[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Priority Queues?
- From: Geoff Leyland <geoff_leyland@...>
- Date: Wed, 25 Jul 2007 13:23:52 +1200
Hi,
I'm new here. I've been using Lua for a while in a discrete-event
transport simulation, and it's been fantastic. I was originally
thinking of using python, and I'm very pleased I looked a little
further!
The simulation is mostly written in C++, and I started using Lua for
its configuration files which turned out to be very effective and
easy, so the next step has been to make the simulation a Lua module,
which has made the whole thing far more useful and easy to test.
What I'm thinking of next is writing some of the simulation logic in
Lua. This seems to mean storing "pointers to Lua objects" (functions
or callable tables) on the C++ side which should be ok. I think where
I'd like to get to, or at least try as an exercise, is having
something like a std::priority_queue containing "pointers to Lua
functions".
I'm not quite sure how to go about this. The queue might get longish
- 100,000's of elements, and I'd like the solution to be moderately
efficient.
One way I can imagine doing this at the moment is to create a table
in the registry and store the lua functions at indexes in that table,
and then store those indexes in the priority_queue. That way, Lua is
aware that I'm interested in those objects, and I have a way of
keeping hold of them. Popping to top off the priority queue will
also mean removing an element from the table, which I imagine will be
a little inefficient. Possibly more than I'd like, but I'll have to
see.
The other approach I can think of (which I don't really like) is to
look at the Lua internals to see if I can hold on to a "lua object"
other than in a stack or the registry, and if I can make sure the GC
knows what I'm up to. Like I said, probably not a good idea.
Does anyone have any advice on how to approach this? Have any
experience with storing a largish number of lua variables in a C data
structure? Am I missing anything obvious? Is there anywhere this
kind of question has already been covered?
Thanks for your time,
Geoff