[Vm-dev] help on creating plugin

Yoshiki Ohshima yoshiki at vpri.org
Wed Sep 17 21:50:52 UTC 2008

> > 2) what is the right way to use strings? now, I'm obtaining them as
> > parameters, but the string comes without final zero, so C does not works
> > fine... because of that, I'm copying them into a new variable (memory
> > allocated with malloc and freed after use), but it does not seems to be very
> > performant... is there a better way?
> you have to copy string into buffer and terminate it with 0
> character.


  But if possible, avoid using malloc() and free().  Instead, use the
memory in Squeak's object memory.  That way you can avoid
fragmentation.  Just right before the call to primitive (or in the
primitive), copy the content of the orignal string into another String
whose size is one bigger than original (by #replaceFrom:to:with:), and
do basicAt: 0 at the end.  You could possibly keep the buffer around
and reuse it, as long as the size of the String fits in the buffer.

> > 3) in general, what is the best way to return Strings into Squeak? I have to
> > create an instance with interpreterProxy>>instantiateClass: each time?
> >
> yes

  If you know the size of string that is returned, again you can pass
an instance of String from image to the primitive and fill it in.
Primitive code looks cleaner in that way.

> > Well, I have many doubts about how to optimize my code... where can I look
> > to see some example code?
> >
> you can look at plugins code, which you already having in VM.

  Or, you can just show the code to us!

-- Yoshiki

More information about the Vm-dev mailing list