All Downloads are FREE. Search and download functionalities are using the official Maven repository.

z3-z3-4.13.0.src.util.pool.h Maven / Gradle / Ivy

The newest version!
/*++
Copyright (c) 2006 Microsoft Corporation

Module Name:

    pool.h

Abstract:

    Object pool.

Author:

    Leonardo de Moura (leonardo) 2007-02-15.

Revision History:

--*/
#pragma once

#include "util/util.h"
#include "util/vector.h"

template
class pool {
    ptr_vector m_objs;
public:
    ~pool() {
        std::for_each(m_objs.begin(), m_objs.end(), delete_proc());
    }

    T * mk() {
        if (m_objs.empty()) {
            return alloc(T);
        }
        else {
            T * r = m_objs.back();
            m_objs.pop_back();
            return r;
        }
    }
    
    void recycle(T * obj) {
        m_objs.push_back(obj);
    }
};






© 2015 - 2024 Weber Informatics LLC | Privacy Policy