A few Python C/C++ interaction questions

Started by
-1 comments, last by Misery 12 years, 3 months ago
Hello, biggrin.png

I am willing to make a Python class, which has C/C++ 2D array, let's say:


A=AClass()
v=A[1][1] #get some value


I want AClass to be an interface to an ordinary C/C++ 2D array, for exmple for array like this:

int N=SomeValue, M=SomeValue;
double **arr= new double*[N];
for (int i=0;i<N;i++) arr=new double[M];


And here are few questions that arised:
1) It will be compiled only using MSVC and GCC (Win and Linux): can I use new/delete operators or I do have to use malloc and free functions? I've read that using C++ syntax shouldn't be a problem if i am using C++ linker and compiler. Will new/delete work? Can I make it all in cpp source files?

2) Will Python manage these C/C++ array with it's garbage collector? What I mean is: will this array be allocated in Python memory pool? Or should I create my own pool and manage those matrices? Or better: how do I allocate those on Python memory pool? It is importatnt, because those arrays will be allocated and deallocated a lot of times, and I would like to avoid memory fragmentation.

3) how do I access elements of this array? Is it enough to create for example __getitem__(self,i) method in C/C++?

As usually thanks for any help or suggestions.
Best Regards,
Misery

This topic is closed to new replies.

Advertisement