Jump to content
  • Advertisement
Sign in to follow this  
Misery

A few Python C/C++ interaction questions

This topic is 2531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!