Trying to write a plugin - how to store a pointer
Andreas Raab
andreas.raab at gmx.de
Tue Jan 24 00:00:42 UTC 2006
Generally, it's safer to use indexes (handles) that the VM maps to
appropriate pointers. That's because otherwise a restarted image might
invoke the primitive with a pointer from a previous session.
Cheers,
- Andreas
Todd Blanchard wrote:
> For various reasons, I'm wanting to build a plugin to a library that
> requires me to hold onto pointers to things. This means I need to
> store the pointer in an ivar in a squeak object and use it on
> subsequent calls.
>
> Can I get away with using a SmallInteger for this? Basically doing
> something like:
>
> primNewContext
> | ctx |
>
> self export: true.
> self primitive: 'primCreateContext' parameters: #().
> self var: #ctx type: 'int'.
> ctx := self cCode: 'LIB_NewContext()'.
> ^ctx.
>
> primDestroyContext: ctx
> self export: true.
> self primitive: 'primDestroyContext' parameters: #(SmallInteger).
> self cCode: 'LIB_DestroyContext((void*)ctx)'.
>
> Or is this evil and I should consider a different technique?
> If this is evil, what is the good way to store external addresses in
> ivars?
>
> Thanks
>
>
More information about the Vm-dev
mailing list