472,328 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Boost::Python - Question about object ownership and lifetime

Hi folks, new to Boost Python and struggling to build a prototype at
work. I thought I'd start with a conceptual question to help clarify
my understanding. I already have a basic prototype working nicely but
I'm having a few issues, which I may post about later.

A brief functional rundown of what I'm trying to prototype. Hopefully
my explanation doesn't get too confusing!

I'm embedding a python module into an application; Python will provide
application logic, responding to events such as timers expiring or the
user clicking widgets.

I have the following classes I'm exporting to Python:

Entity, DerivedEntity, EntityList (contains pointers to Entity).

They all have varying types of copy/constructors, e.g. some are
private, some have non-const copy constructors etc. It's inherited
code that I can't mess with so I'm stuck with it.

So the typical logic flow I'm looking at is:

C++ Application:

- Create an instance of EntityList called entity_list, populate with
many instances of DerivedEntity.
- Create an instance of EntityList called change_list
- Invoke python function passing entity_list and change_list as


- For each entity in entity_list:
- Invoke C++ function clone_entity, pass entity as parameter

C++ Application:

- Create clone of entity like this --DerivedEntity* entity_copy
= new DerivedEntity(entity)
- return entity_copy to Python

Back in Python again:

- Apply logic to entity_copy returned from clone_entity C++
- If entity_copy updated add to change_list

Back in C++ Application:

- For each new_entity in change_list
- Apply further logic to new_entity
- Delete new_entity pointer
- Clear the change_list

I'm having problems in my prototype - it looks like I have a memory
leak but I'm not sure where. So my question is, what should I be aware
of in this logic flow with regards to object ownership and lifetime?

When I receive entity_copy in Python, returned from clone_entity, what
happens to this object when I insert it into change_list and
subsequently delete the C++ pointer? I don't know how to prove that
the Python object is being deleted and isn't hanging around due to a
lifetime issue,

I guess my main problem is that I'm entirely sure I understand object
ownership - who owns what object when it's created in C++, passed to
Python and then returned back to C++ to be deleted.

So if any of this makes sense, I would greatly appreciated any
suggestions or help. I'm very impressed with Boost Python so far but
my own lack of understanding is holding me back I think.

Thanks again
Jun 27 '08 #1
0 1207

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Steve Knight | last post by:
Hello, I'm new to Boost & Python and I'm diving straight in by trying to write an extension module to a third party library. Foolishness...
by: Gouda Man | last post by:
I'm planning to write a large program that will have advanced scripting in python in which the scripter will subclass c++ objects to add...
by: Li Daobing | last post by:
I can't use .def(str(self)) I write a simple example, without `str', I can build it well, but with this one, I can't build //Rational.cpp...
by: Pedro | last post by:
Hello pythonians! ;-D , I have a little problem when I expose (assisted by boost.python) classes with virtual functions, specially with...
by: Shawn McGrath | last post by:
Hi, I'm trying to expose a C++ class' internals to python via boost::python. I can do integer/boolean functions fine, but as soon as I do a string...
by: Stou Sandalski | last post by:
Hi, I have a python library created by wrapping the C++ library using Boost.Python, the problem is that the wrappers are not very pythonic.......
by: devito | last post by:
hi there, for some days i try to build the boost.python tutorial "hello world" without bjam on winxp by using mingw. so i wrote a *.bat-file...
by: =?ISO-8859-1?Q?Fr=E9d=E9ric_Degraeve?= | last post by:
Hello, I tried this code with vs7-8 and boost1.34.1-1.35.0 and my python is a 2.4. The call to Cpython works well but boost::python doesn't work....
by: Stodge | last post by:
I've exposed a C++ class to Python using Boost Python. The class, let's say it's called Entity, contains private static data, which is an array of...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.