From: klaas.holwerda <kho...@xs...> - 2006-01-11 22:57:48
|
John Labenski wrote: >>If several lua_State need to share data, that can be done using a second >>Smart Pointer inside wxLuaState. >> >> > >You still need a way to associate many lua_States with a single group >of data structures. I'm not sure how a smart pointer would help here. > > The idea of smart pointers is that there are many Smart pointers pointing to the same data structure. How many the count is, is held within that data structure by the refcount. So the idea is exactly that the same structure/class instance is referenced/shared by several other objects, which hold a smart pointer to that structure/class as a member . So if it would be possible to couple each new lua_State to a wxLuaState, where the last has a smart pointer to the shareddata structure/class, that would be oke. This is i think you had in mind too, but doing it using refcounting the wxWidgets way, which is i think harder. >>It will be cleared properly if all wxLuaStates's are released ( no more >>smart pointers to it ). >>I used hierarchies of smart pointers for storing drawing objects, and it >>works great. >> >> > >Deletion is not so much a problem, I will look back at your smart >pointers. Another reason to have the wxObject ref mechanism is that >you can have a delayed construction, eg. make a wxLuaState a member of >a class and then Create it as necessary or not at all. > > Same with smart pointers i think. It initializes to zero, and once it is assigned a wxLuaState object, it will hold it. In principle a smart pointer acts almost like a normal pointer in mnay cases, only it deletes the object pointed to only when there or no more references. We have another even smarter pointer, which is able to reset all other smart pointers pointing to the same object. ( the object pointed to, has a list of all Smart pointer pointing to it. ) So it depends on what is needed. > > >>What is exactly the reason you choose the current form of ref counting? >> >> > >So that when you pass a wxLuaState to a wxLuaCallback (a handler for a >wxEvent) and then close the lua_State you want the wxLuaCallback to >know that the lua_State has been closed. > That sounds like the smarTer pointer version;-) > It's a simple way to let >anyone who's given a wxLuaState that the lua_State is good or not. If >you just use pointers to the lua_State you have to track them all and >NULL them to avoid someone trying to use them. This can happen with >delayed window deletion in wxWidgets. > > I see, i recognize this, often had that problem in wxWidgets. Who is normally deleting a created lua_State? Is wxLua able to notice this event? Hope it helps a little to decide what is best, Klaas |