I am using SWIG to create a Python library. I would like to know if calling SWIG_NewPointerObj with own parameter set to SWIG_POINTER_OWN allocates new memory.
Asked
Active
Viewed 227 times
0
-
The `SWIG_POINTER_OWN` flag is only about running the destructor. See https://stackoverflow.com/questions/7223327/what-does-the-last-argument-to-swig-newpointerobj-mean – Henri Menke Jul 20 '18 at 08:30
-
Thanks for the answer. You say only about running the destructor. But it is also about freeing memory, isn't it? – Ratmil Jul 20 '18 at 14:41
-
I'm not so sure what you mean by memory allocation. As I understand it the function `SWIG_NewPointerObj` receives a pointer to a C/C++ object that you have created and wraps it in a Python object. I don't know the internals of the Python interpreter, so I can't say whether creating a Python object has to allocate. For sure no memory has to be allocated for your C/C++ object because it has to exist already when calling `SWIG_NewPointerObj`. When you say `SWIG_POINTER_OWN` you tell the interpreter that it is now responsible for cleaning up the memory for the C/C++ object. – Henri Menke Jul 28 '18 at 01:41
-
Hi, thanks for all the comments. Yes, Henri Menke, you are right. I had missunderstood the use of this function. – Ratmil Jul 29 '18 at 12:51