Re: Protecting memory
Nigel Atkinson <[email protected]> Thu, 1 Dec 2011 09:27:46 +1100
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Colin, You can wrap your pointers up in a smart pointer, made specifically for the job. I made what I call a ward_ptr, a class that is really just a wrapper around a raw pointer, except it has a member called 'invalidate' which sets the raw pointer it stores to null. You call this on the C++ side whenever the object it points to is deleted. If the smart pointer is used (dereferenced) while its stored pointer is null, it throws an exception - which if that happens inside a function/ method called from luabind, gets turned into a lua error by luabind. You could have a "isvalid" method too, in order to check a pointer rather than just using it and causing an exception. I don't in mine, as I use it with a library I didn't write bound with luabind. Heres a link to some code! Feel free to use it. https://github.com/merlinblack/Game-Engine-Testbed/blob/master/include/ward_ptr.h Nigel On 30/11/2011, at 10:39 PM, Colin GILLE / congelli501 wrote: > Hi, > > I'm new to this mailing list and quite new to luabind too. > I'm creating a 2D game engine with lua scripting and I wich to > protect the memory (against segmentation faults). > Some of my functions return pointers to objects, and these objects > can be deleted later by the engine. > When the user uses a pointer, I would like to check if this pointer > is still valid before using it in my C++ code. > I can easily do that if the pointer in a function argument but I > don't know how to that when the user use the member of the object. > > What is the good way to do it with luabind ? > > Thanks in advance ! > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d_______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity, and more. Splunk takes this data and makes sense of it. IT sense. And common sense. http://p.sf.net/sfu/splunk-novd2d