PetrPPetrov / beautiful-capi

Beautiful Capi is a tool which automates the creation of compiler-independent and binary compatible C++ libraries across different C++ compilers
GNU General Public License v3.0
33 stars 4 forks source link

Implement manual handling of objects in the library heap #36

Open PetrPPetrov opened 7 years ago

PetrPPetrov commented 7 years ago

Something like that:

class Printer
{
public:
    void Show() {
        printer_show(this);
    }

    static void * operator new(size_t size) {
        assert(size == sizeof Printer);
        return printer_create();
    }

    static void operator delete(void * obj, size_t size) {
        assert(size == sizeof Printer);
        printer_destroy(obj);
    }
};

The idea was contributed by @vdimas