-
Notifications
You must be signed in to change notification settings - Fork 12
Integrating Cxx code into Cando
For example - I added two C++ source files to Cando: cando/src/chem/maxcliqueseq.cc
and cando/include/cando/chem/maxcliqueseq.h
.
In the maxcliqueseq case a new class chem::Dimacs_O is exposed to Common Lisp.
I tell the garbage collector how to deal with the new class using this:
template <>
struct gctools::GCInfo<chem::Dimacs_O> {
static bool constexpr CanAllocateWithNoArguments = true;
static bool constexpr NeedsInitialization = true;
static bool constexpr NeedsFinalization = true;
static GCInfo_policy constexpr Policy = normal;
};
The NeedsFinalization = true
tells the garbage collector that when it collects the object that it should invoke the destructor for the C++ class. This is necessary because the Dimacs_O class includes fields that are C++ std objects like 'vector' and they need to be cleaned up or they will leak memory.
If you don't use C++ standard classes - then nothing needs to be cleaned up. Clasp's classes are largely designed so that they don't need finalization or cleanup - they can be simply abandoned by the garbage collector and this is more efficient.
This ensures that the file is compiled and installed with the rest of the source code.
This ensures that the classes defined in the header file are known to the garbage collector.
CL_DEFUN
core::T_sp chem__find_maximum_clique_search(Dimacs_sp dimacsGraph, int numThreads, int numJobs) {
...
}