Mantis - Squeak
Viewing Issue Advanced Details
3692 FFI feature N/A 05-21-06 22:24 07-14-06 15:06
nicolas cellier  
andreas  
normal  
closed 3.9  
fixed  
none    
none 3.9  
0003692: [FFI][NEW FEATURE] ExternalAdress auto-free
when ExternalAddress class>>allocate: is used, care must be taken to invoke ExternalAddress>>free to release external heap memory.
This is not easy and involves a lot of ensure: guards...

An alternative is to use a weak registry.

ExternalAddress gcallocate: use ExternalAddress finalizationRegistry, that is Object finalizationRegistry by default, but maybe a specific registry in ExternalAddress would be a good idea (not implemented).

Executor is a clone of the address, as provided by default in object.

Beware: never invoke free directly on a gcallocated ExternalAddress (no guard in this implementation).
 FFI-ExternalAddress-autoFree-Feature.1.cs [^] (1,422 bytes) 05-21-06 22:26

Notes
(0005025)
andreas   
05-21-06 23:54   
This looks very useful, thanks. One question though: Why did you have to reimplement shallowCopy? Shouldn't the implementation in Object (using a primitive) be enough?
(0005026)
nicolas cellier   
05-22-06 13:13   
Yes, super shallowCopy should do the work.
Unfortunately, in my 3.9a, it calls new: instead of basicNew:, and that fails because ExternalAddress new: raise an error.

I think Object>>shallowCopy should use basicNew basicNew: basicAt: basicAt:put: instVarAt: instVarAt:put: and nothing else (better if in a primitive).

Implementing ExternalAddress>>shallowCopy is a workaround...
(0005030)
nicolas cellier   
05-22-06 22:24   
I did not have an image when writing last note.
Object>>shallowCopy is just fine.

super shallowCopy is not in Object, it is Sequenceable>>shallowCopy
that is defined as copyFrom:to:, that will call new:

Implementing shallowCopy there will avoid implementing postCopy for some collection, but it also make the shallowCopy not shallow (example Text new shallowCopy does not share string nor runs). Is it really a good idea?
(0005033)
andreas   
05-23-06 22:18   
Integrated in http://source.squeakfoundation.org/FFI/FFI-ar.9.mcz [^]
(0005895)
MarcusDenker   
07-14-06 15:06   
in 70XX