/stack_pimpl

PIMPL without the heap

Primary LanguageC++MIT LicenseMIT

As with PIMPL, this is a compile firewall to keep the compile times and changes in one section from cascading and imacting your whole project with a recompile. They do not keep things secret as one can always look at the binary and pick it apart(e.g. objdump). So with that, this design keeps the data(state) in the public facing class. This allows one to keep everythign stack allocated instead of defaulting to the heap. When creating objecs like this en mass(A vector of them) or created and destroyed often, this is a runtime win. The private/firewalled part is a proxy that mirrors the public interface with an extra this pointer from the public part as an argument. The proxy class is also a friend class to the public class. Because only the proxies header(in this case private.h) has static members that mirror the public members on the public class, it limits the interaction between your classes users and it's implementation, as it is also with unique_ptr(or whatever pointer/heap way) based PIMPL designs. So changes in private.cpp(it does all the work) are only reflected in that one file's compile time. This file can bring in heavy templates or algorithm code that may have large compile times without affecting the rest of the project.