Program Listing for File AllocationStrategy.hpp¶
↰ Return to documentation for file (umpire/strategy/AllocationStrategy.hpp
)
//////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2018, Lawrence Livermore National Security, LLC.
// Produced at the Lawrence Livermore National Laboratory
//
// Created by David Beckingsale, david@llnl.gov
// LLNL-CODE-747640
//
// All rights reserved.
//
// This file is part of Umpire.
//
// For details, see https://github.com/LLNL/Umpire
// Please also see the LICENSE file for MIT license.
//////////////////////////////////////////////////////////////////////////////
#ifndef UMPIRE_AllocationStrategy_HPP
#define UMPIRE_AllocationStrategy_HPP
#include "umpire/util/Platform.hpp"
#include <string>
#include <memory>
#include <cstddef>
namespace umpire {
namespace strategy {
/*!
* \brief AllocationStrategy provides a unified interface to all classes that
* can be used to allocate and free data.
*/
class AllocationStrategy :
public std::enable_shared_from_this<AllocationStrategy>
{
public:
/*!
* \brief Construct a new AllocationStrategy object.
*
* All AllocationStrategy objects must will have a unique name and id. This
* uniqueness is enforced by the ResourceManager.
*
* \param name The name of this AllocationStrategy object.
* \param id The id of this AllocationStrategy object.
*/
AllocationStrategy(const std::string& name, int id);
virtual ~AllocationStrategy() = default;
/*!
* \brief Allocate bytes of memory.
*
* \param bytes Number of bytes to allocate.
*
* \return Pointer to start of allocated bytes.
*/
virtual void* allocate(size_t bytes) = 0;
/*!
* \brief Free the memory at ptr.
*
* \param ptr Pointer to free.
*/
virtual void deallocate(void* ptr) = 0;
/*!
* \brief Get current (total) size of the allocated memory.
*
* This is the total size of all allocation currently 'live' that have been
* made by this AllocationStrategy object.
*
* \return Current total size of allocations.
*/
virtual long getCurrentSize() = 0;
/*!
* \brief Get the high watermark of the total allocated size.
*
* This is equivalent to the highest observed value of getCurrentSize.
* \return High watermark allocation size.
*/
virtual long getHighWatermark() = 0;
/*!
* \brief Get the current amount of memory allocated by this allocator.
*
* Note that this can be larger than getCurrentSize(), particularly if the
* AllocationStrategy implements some kind of pooling.
*
* \return The total size of all the memory this object has allocated.
*/
virtual long getActualSize();
/*!
* \brief Get the platform associated with this AllocationStrategy.
*
* The Platform distinguishes the appropriate place to execute operations
* on memory allocated by this AllocationStrategy.
*
* \return The platform associated with this AllocationStrategy.
*/
virtual Platform getPlatform() = 0;
/*!
* \brief Get the name of this AllocationStrategy.
*
* \return The name of this AllocationStrategy.
*/
std::string getName();
/*!
* \brief Get the id of this AllocationStrategy.
*
* \return The id of this AllocationStrategy.
*/
int getId();
protected:
std::string m_name;
int m_id;
};
} // end of namespace strategy
} // end of namespace umpire
#endif // UMPIRE_AllocationStrategy_HPP