/* 
 * Copyright (C) 2020,  Paul Sheer. All rights reserved.
 * 
 * This software is provided without warranty. The author(s) disclaim liability for damages
 * related to this software. All risk is assumed by you.
 * 
 */

#ifndef DFWMALLOC_CXX_H
#define DFWMALLOC_CXX_H

#include "dfwmalloc.h"
#include "dfwmalloc_inline.h"


class dfwmalloc_class
{
public:
    dfwmalloc_class(size_t size) {
        if (dfwmalloc_prepare (&m, size)) {
            abort ();
        }
    }

    ~dfwmalloc_class() {
    }

    struct malloc_calc m;

private:
    dfwmalloc_class(const dfwmalloc_class &);
    void operator=(const dfwmalloc_class &);

};


template<class dfw, dfw &instance>
class malloc_object
{
    public:

    static void *operator new(size_t size) 
    {
        (void) size;
        return malloc_precalc (&instance.m);
    }

    static void  operator delete(void *p, size_t)
    {
        free_precalc (&instance.m, p);
    }
};

#endif          /* !DFWMALLOC_CXX_H */

