comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Reference counting
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Reference counting [message #55818] Tue, 11 September 2007 23:32 Go to previous message
Robbie is currently offline  Robbie
Messages: 165
Registered: February 2006
Senior Member
I am using reference counting to automatically free pointers which are
no longer in use. I've come across a problem when I use save and
restore. I find that I really need to recalculate the number of
references after I restore an object. Is there any way to
programatically determine the number of references to a pointer?

Thanks

Robbie


Example code attached:



pro refcount::GetProperty, VALUE=value

if (arg_present(value) and (n_elements(*self.value) gt 0)) then value
= *self.value

end



pro refcount::SetProperty, VALUE=value

if (n_elements(value) gt 0) then *self.value = value

end



function refcount::Copy

obj =
obj_new('refcount',P_VALUE=self.pValue,P_REFERENCE=self.pRef erence)

*self.pReference++

return, obj

end



pro refcount::Cleanup

*self.pReference--

if (*self.pReference le 0) then begin

ptr_free, self.pReference

ptr_free, self.pValue

endif

end



function refcount::init, P_VALUE=pValue, P_REFERENCE=pReference,
VALUE=value

if (n_elements(pValue) gt 0) then self.pValue = pValue $

else self.pValue = ptr_new(/ALLOCATE_HEAP)

if (n_elements(pReference) gt 0) then self.pReference = pReference $

else self.pReference = ptr_new(1)

if (n_elements(value) gt 0) then *self.pValue = value

return, 1b

end



pro refcount__define, struct

struct = {refcount, $

pValue: ptr_new(), $

pReference: ptr_new() $

}

end



pro refcount_example1

a = obj_new('refcount',VALUE=indgen(100))

b = a -> copy()

obj_destroy, [a,b]

help, /heap

end



pro refcount_example2_restore

restore

obj_destroy, [a]

help, a

end



pro refcount_example2

a = obj_new('refcount',VALUE=indgen(100))

b = a -> copy()

save, a

obj_destroy, [a,b]

help, a, b

refcount_example2_restore

help, /heap

end
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Reading Raw Image
Next Topic: Re: Widgets to ION JAVA

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 20:13:32 PDT 2025

Total time taken to generate the page: 0.00544 seconds