Jump to content

  • Log In with Google      Sign In   
  • Create Account


A few Python C/C++ interaction questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 Misery   Members   -  Reputation: 247

Like
0Likes
Like

Posted 08 January 2012 - 01:37 AM

Hello, Posted Image

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[i]=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

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS