[C++-sig] C++ new/delete with python

Dan Eloff dan.eloff at gmail.com
Thu Dec 2 00:19:41 CET 2004

So you want a class member defined as an array allocated dynamically
on the heap. You can do this, but you may or may not be able to access
it directly in python. I don't know if boost::python has an array
wrapper, check the docs, that's what they are there for. As for
deleting the array, you will have to do that in C++ (in the objects
destructor??). Your code is invalid btw, it should be test::objects =
new int[10]; But i would recommend you intialize dynamic arrays in
test's constructor, it just makes more sense.


On Thu, 25 Nov 2004 09:15:52 +0000 (UTC), Chris Targett <xin at xlevus.net> wrote:
> I've got some code.
>   class test {
>      test(*int);
>      int *objects;
>   };
>   objects = new int[10];
> I want to expose my class `test` to python via Boost, Is there anything special
> I have to do to get this to expose properly?
> I'm not too fussed about the constructor but if its workable then thats cool.
> Is it possible to have a `new` defined array work within python?
> Thanks
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig

More information about the Cplusplus-sig mailing list