I have Lisp functions that wrap C wrappers for C++ functions that contain a new operator. The C wrappers have to stay the same I can't change those but I was advised to update my method of GC.
Here are the C wrappers:
Mat* cv_create_Mat() {
return new Mat();
}
void cv_delete_Mat(void* ptr) {
delete (~Mat*)ptr;
}
Here are the Lisp wrappers for them:
(defcfun ("cv_create_Mat" mat) (:pointer mat)
"MAT constructor")
(defcfun ("cv_delete_Mat" del-mat) :void
(ptr :pointer))
In a loop, as below, I would normally after calling a MAT function, delete it when I'm done with it manually with DEL-MAT, but I heard there was a better way by actually entering in the DEL-MAT function into Lisps natural GC methods so it would know when it comes across a function with a new
it should call delete to get rid of it when it know i'm done with it.. The thing is I could use help to get started. Hopefully a concrete example of how to do this so I don't have to call DEL-MAT manually
(dotimes (n 1000)
(setf m (mat))
(del-mat m))