perl memry free problem

S

sachin

Hi All

I have written a perl extension for a library mymodule I have used
swig to genarate this .
In this module there is a function get_prop which has one in
parameter and two out parameter

sub get_obj_prop {
($ret,$prop,) =&mymodule::get_prop($obj);
if($ret==$mymodule::MY_EOK) {
print "OK \n";
}
else {
print "Error $ret \n";
}
}

all variables have a global scope
$prop is a pointer to struct obj_prop

$prop is a pointer to a structure allocated by the library
when i call this function second time or i assign some other prop
structure pointer like
$prop = $prop1;
the perl internally calls
the delete_obj_prop function which deletes the structure pointed by
$prop
I dont want such thing to happen because the library internally takes
care of the allocated memory the library maintains the cache of the
allocated memory
Is there is any way so that i can prevent perl from freeing the
structure

Thanks in advance
Sachin.
 
M

Mark Clements

sachin said:
all variables have a global scope
$prop is a pointer to struct obj_prop

$prop is a pointer to a structure allocated by the library
when i call this function second time or i assign some other prop
structure pointer like
$prop = $prop1;
the perl internally calls
the delete_obj_prop function which deletes the structure pointed by

If you reassign $prop then the reference count of to whatever it was
pointing is reduced by one, and if there are no other references to that
object then it is liable to be garbage-collected. Or am I misreading this?

Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top