Memory management when using PythonCall #264
Replies: 3 comments 2 replies
-
Maybe you could post what you have tried. If you create an array in Julia and pass it to Python via PythonCall then by default the underlying array is wrapped so that modifying the array from Python modifies the original. |
Beta Was this translation helpful? Give feedback.
-
I think the problem might be that the Python code I am trying to wrap requires numpy arrays, and PythonCall only creates Arrays. When I convert to a numpy array, this allocates new memory. Is there a way to accomplish what I am trying to do without memory allocation within Python?
|
Beta Was this translation helpful? Give feedback.
-
I think you're focussing to much on allocations here. There is indeed an allocation, but that's because creating a new object in Python always does a small allocation - but it's fast because Python has an allocator optimised for lots of small short-lived allocations. What's important is that doing As you mentioned, if you change the dtype of the array ( |
Beta Was this translation helpful? Give feedback.
-
What is the best way to manage memory when working with PythonCall? I would like to allocate memory in Julia, then make a call to a Python function that modifies what I have passed in, without allocating any new memory. Can you post an example of how to do this using PythonCall? I have been trying, but running into issues.
Beta Was this translation helpful? Give feedback.
All reactions