2012/12/23 Igor Stasenko siguctua@gmail.com:
On 23 December 2012 22:25, Nicolas Cellier nicolas.cellier.aka.nice@gmail.com wrote:
Ah OK, thanks, I get it... Two questions remain:
- how to access addGCroot: from within a SmartSyntaxInterpreterPlugin ?
interpreterProxy addGCroot: ...
Hmm, in NB you used a different strategy... First, you defined a NBInterpreterProxy to perform a simpleCall to addGCRoot() after registering this function in class method #proxyFunctionsData unless it is from #CogProxyFunctionsData (why two?) Then, no plugin calls addGCRoot: directly. Instead you defined a primAddGCRoot: in order to use it from within the image. That's a bit too much for a helpful simple example.
I fail to see how this easily transpose to a vanilla VMMaker and it's native InterpreterProxy. I think I'll have to hack InterpreterProxy to give access to addGCRoot: unless there is more magic I missed in the code generator...
Nicolas
- when do you need to register (re-register)?
- once at image startup ?
yes,at image boot time. when session changes.
- after each snapshot ?
not here
There is no stupid question ;) well more or less...
I think I'll have a look at NativeBoost indeed...
Nicolas
2012/12/23 Igor Stasenko siguctua@gmail.com:
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@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.
-- Best regards, Igor Stasenko.