1 (in-package :sb-bsd-sockets-internal)
4 "Allocate foreign memory in some way that allows the garbage collector to free it later. Note that memory allocated this way does not count as `consed' for the purposes of deciding when to gc, so explicitly calling EXT:GC occasionally would be a good idea if you use it a lot"
5 ;; we can attach finalizers to any object, and they'll be called on
6 ;; the next gc after the object no longer has references. We can't
7 ;; however make the finalizer close over the object, or it'll never
8 ;; have no references. I experimentally determined that (sap-alien
9 ;; (alien-sap f)) is not EQ to f, so we can do it that way
10 (let* ((memory (make-alien (unsigned 8) size))
11 (alias (sap-alien (alien-sap memory)
13 (sb-ext:finalize memory
15 (free-alien alias)))))