[Vm-dev] How to addGCRoot: ? help requested

Igor Stasenko siguctua at gmail.com
Sun Dec 23 20:59:39 UTC 2012


addGCRoot()
takes a pointer to some memory location, where root object will be stored.

sqInt * mem;

mem = malloc(4);
*mem = someOop;
addGCRoot(mem);

now, to read a reference to 'someObject' at any place you can just do

someOop = *mem.

often you may want to register multiple objects for use.
you can , of course, use addGCRoot() per each of them,
or, just use an array to store unlimited number of objects as roots
(that way you don't risk overflowing extra roots table, as well as can manage
that array at image side, and at cost of extra indirection).

If you want a working example you can look at NBExtraRootsRegistry
implementation,
which is part of NativeBoost, how i using it.

On 23 December 2012 21:34, Nicolas Cellier
<nicolas.cellier.aka.nice at gmail.com> wrote:
>
> I wanted to experiment a plugin and need to register a couple of
> classes that some primitive will test/instantiate.
> The ugly way is to pollute specialObjectArray...
> But #recreateSpecialObjectsArray recommend using addGCRoot()
> Fine, I'd like to try.
>
> What I'd like to do is register my couple of classes in a
> primRegister() primitive
> (once for all or at each image startup, or at each snapshot, whatever...)
> Then to later use the registered classes in primDoSomething().
>
> I can see ObjectMemory>>addGCRoot: but unfortunately, absolutely no
> sender of it to serve as an example...
> I even don't know how to access the objectMemory from within a
> SmartSyntaxInterpreterPlugin ?
> I can only see a interpreterProxy and
>
> Then how to retrieve my registered objects? they are store in the
> extraRoots at some index, but that index is not returned by
> addGCRoot:...
> Anyway, the index could change thanks to removeGCRoot:, so I'm stuck here...
> I must be missing something...
> Or maybe addGCRoot: is just here to prevent an Object to be garbage
> collected but does not really offer a registering service...
>
> If you know about any documentation/example hanging around or have
> some clues I'll be happy that you share them !
>
> Last note, I'm in a VMMaker oscog flavour...
>
> Nicolas



-- 
Best regards,
Igor Stasenko.


More information about the Vm-dev mailing list