[C++-sig] Whats going on under the hood?

David Sveningsson eXt at sidvind.com
Thu Jan 18 00:19:30 CET 2007


I want to understand how python/boost handles the memory.

Take a look at the following code:

void add(Base& e){
     list->add(e);	// Permanently stores the object
}

BOOST_PYTHON_MODULE(Foo){
     def("add", &add);

     class_<Base>("Base")

     ;
}

and this:

class Derived (Foo.Base):
     pass

add(Derived())

What happens when this code is run? What happens when the python scope 
ends? May I safely use the reference in C++? Should I delete the 
reference afterwards? What happens if I delete the reference, does it 
delete memory allocated from python too?

I should mention that I'm not really familiar with how python manages 
the memory either. Reference counting?

I hope to get some answers to my questions.


-- 


//*David Sveningsson [eXt]*

Freelance coder | Game Development Student
http://sidvind.com

Thou shalt make thy program's purpose and structure clear to thy fellow 
man by using the One True Brace Style, even if thou likest it not, for 
thy creativity is better used in solving problems than in creating 
beautiful new impediments to understanding.



More information about the Cplusplus-sig mailing list