Hi, Indeed. We could malloc and set-finalizer! and that should work and be safe. However, as far as I understand, this approach has some disadvantages:
- malloc is relatively slow compared to chicken's internal allocation (eg make-string) that uses the stack - there is a practical limit on finalizers that Chicken can handle - large number of set-finalizer!s will slow things down I forgot to mention that I don't want to go for this approach in this case because it will impact us heavily, since we allocate oid objects a lot. I believe that is why Evan went for the alternative make-primitive method. So I think we really _want_ to involve the Chicken GC, but we need to give it some more info than just a #<c-pointer>. I've used this make-blob approach that is in the attached patches before, with success. Unfortunately, it doesn't integrate well with the foreigners egg, but I hope it is still a good candidate here for the oid, buf and revspec structures. K. On Mon, Jun 14, 2021, 07:10 megane <[email protected]> wrote: > > Kristian Lein-Mathisen <[email protected]> writes: > > > From what I gather, there is no way to allocate memory and return a > pointer > > to it, safely, in CHICKEN. > > Won't the garbage collector potentially overwrite whatever region was > > allocated since it has no way of knowing it? > > There's allocate from chicken.memory that does just that. It allocates > using 'malloc', and chicken GC will have no knowledge or way of > interfering with the memory. Free the memory using 'free' from the same > module. > >
