Re: Protecting memory
Ryan Pavlik <[email protected]> Thu, 1 Dec 2011 09:06:11 -0600
| Newsgroups | gmane.comp.lang.lua.bind.user |
|---|---|
| Message-ID | <CABMFTE8B3uv0OwhpV=0goewpiH5+_WU4MgnNqDuM5wb=KqpKSg@mail.gmail.com> |
This seems like a good time to use boost's shared_ptr and weak_ptr. Ryan On Wed, Nov 30, 2011 at 4:27 PM, Nigel Atkinson <[email protected]>wrote: > 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 > _______________________________________________ > luabind-user mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/luabind-user > -- Ryan Pavlik HCI Graduate Student Virtual Reality Applications Center Iowa State University [email protected] http://academic.cleardefinition.com ------------------------------------------------------------------------------ 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