How to sync Lua and C++ garbage collection -
I am trying to embed lava in an existing C ++ application and for this it is inherited from a class by one The standard process has worked out. I see that the serious problem is that if a highlighted object is deleted or deleted in C ++ environment, a call from Lua will crash if the program is being removed by using the 'Delete' program I could probably write a cover on Leah being taken to care for the delocation, but if memory was allocated by C ++ and when the scope of the appropriate variable is over
thanks.
Thank you. Thank you. Thank you. Thank you.
In general, there is a way to decide what is the owner of which memory, whatever object is owned by each cover. (And therefore will be destroyed by Lea) or by your application.
If you have given Lua the owner of C ++ to an indicator of an object, then you have to find a way to make sure that Lua does not use this pointer before that point where C ++ Eliminates it There are several ways to avoid this: One way to transfer ownership to Lua.
Another way is to use You also promote boost / std :: shared_ptr , which allows you to share between C ++ and Lua If you are doing this manually, then you are creating some non-light user data which is the size of
shared_ptr in Leah. You attach it to Cleanup Metamphthat that will destroy
shared_ptr , and you use placement-new to create share_ptr on Lea user data. In Luvband, there is actually a built-in feature: if you pass
shared_ptr with Lua, they both share the share of memory.
/ std :: weak_ptr . This is an object that you ask to get a
shared_ptr . The idea is that you do not want to keep the indicator around; You temporarily query it, but you only permanently store
weak_peter if the object has lost all its
shared_ptr references, then < After querying the code> weak_ptr , an empty indicator will return.
Comments
Post a Comment