[Vm-dev] How to return an array in a primitive ?
bert at freudenbergs.de
Tue Apr 27 15:04:11 UTC 2010
On 27.04.2010, at 16:18, Mariano Martinez Peck wrote:
>> As Bert says, it is safer to avoid allacations in the primitive. But
>> for an example of how to do it properly, see
>> Note the use of #pushRemappableOop: and popRemappableOop, which is required
>> to prevent the object pointers from changing due to garbage collection.
>> Allocating an object in the primitive can and will invoke garbage
>> collection, which leads to nasty intermittent bugs if you do not
>> use #pushRemappableOop:.
> Thanks Dave. I was just going to ask why it was "unsafe" but you already answered.
Not quite. There is more to it than just remapping oops. Try to imagine what happens if the allocation fails because there is not enough memory, even after GC.
For small allocations there should be enough of a safe margin (hopefully the low-space watcher kicks in early enough). But at least for big allocations you also need to check if they failed.
- Bert -
> I was going to ask an example too, but I got it also :)
> So...perfect. I just write my primitive with something similar to the FilePlugin example.
> Thank you very much to both of you.
More information about the Vm-dev