Skip to content

Commit

Permalink
#871: Removed function template and added arguments for FixedSizedPool
Browse files Browse the repository at this point in the history
  • Loading branch information
Braden committed Dec 3, 2020
1 parent e6477a1 commit 1c2647c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/vt/pool/pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ struct Pool : runtime::component::Component<Pool> {
using SizeType = size_t;
using HeaderType = Header;
using HeaderManagerType = HeaderManager;
template <int64_t num_bytes_t>
using MemoryPoolType = FixedSizePool<num_bytes_t>;
template <int64_t num_bytes_t>
using MemoryPoolPtrType = std::unique_ptr<MemoryPoolType<num_bytes_t>>;
using MemoryPoolType = FixedSizePool;
using MemoryPoolPtrType = std::unique_ptr<MemoryPoolType>;

/**
* \brief Different pool sizes: small, medium, large, and the backup malloc
Expand Down
26 changes: 13 additions & 13 deletions src/vt/pool/static_sized/memory_pool_equal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@

namespace vt { namespace pool {

template <int64_t num_bytes_t>
FixedSizePool<num_bytes_t>::FixedSizePool(SlotType const in_pool_size)
FixedSizePool::FixedSizePool(SlotType const in_pool_size)
: pool_size_(in_pool_size)
{
resizePool();
}

template <int64_t num_bytes_t>
/*virtual*/ FixedSizePool<num_bytes_t>::~FixedSizePool() {
/*virtual*/ FixedSizePool::~FixedSizePool() {
vt_debug_print(
pool, node,
"cur_slot_={}\n", cur_slot_
Expand All @@ -78,8 +76,7 @@ template <int64_t num_bytes_t>
}
}

template <int64_t num_bytes_t>
void* FixedSizePool<num_bytes_t>::alloc(
void* FixedSizePool::alloc(
size_t const& sz, size_t const& oversize
) {
if (static_cast<size_t>(cur_slot_ + 1) >= holder_.size()) {
Expand Down Expand Up @@ -108,8 +105,7 @@ void* FixedSizePool<num_bytes_t>::alloc(
return ptr_ret;
}

template <int64_t num_bytes_t>
void FixedSizePool<num_bytes_t>::dealloc(void* const t) {
void FixedSizePool::dealloc(void* const t) {
vt_debug_print(
pool, node,
"dealloc t={}, cur_slot={}\n", t, cur_slot_
Expand All @@ -125,8 +121,13 @@ void FixedSizePool<num_bytes_t>::dealloc(void* const t) {
holder_[--cur_slot_] = ptr_actual;
}

template <int64_t num_bytes_t>
void FixedSizePool<num_bytes_t>::resizePool() {
// Right now function doubles the vector.
// If not enough slots are used make it smaller
// Needs a function to make the pool larger or smaller
// Also needs an argument for pool size.
// Size should be determined from current usage
//
void FixedSizePool::resizePool() {
SlotType const cur_size = holder_.size();
SlotType const new_size = cur_size == 0 ? pool_size_ : cur_size * 2;

Expand All @@ -137,9 +138,8 @@ void FixedSizePool<num_bytes_t>::resizePool() {
}
}

template <int64_t num_bytes_t>
typename FixedSizePool<num_bytes_t>::SlotType
FixedSizePool<num_bytes_t>::getNumBytes() {
typename FixedSizePool::SlotType
FixedSizePool::getNumBytes() {
return num_bytes_;
}

Expand Down
6 changes: 4 additions & 2 deletions src/vt/pool/static_sized/memory_pool_equal.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
#include <vector>
#include <cstdint>

// Add methods to return the currently used
// memory in the system in order to determine
// how to resize the memory pool.
namespace vt { namespace pool {

static constexpr size_t const small_msg_size_buf =
Expand All @@ -65,7 +68,6 @@ static constexpr size_t const medium_msg_size_buf =
static constexpr size_t const memory_size_medium =
sizeof(EpochTagEnvelope) + medium_msg_size_buf;

template <int64_t num_bytes_t>
struct FixedSizePool {
using ContainerType = std::vector<void*>;
using SlotType = int64_t;
Expand All @@ -75,7 +77,7 @@ struct FixedSizePool {
static constexpr SlotType const fst_pool_slot = 0;
static constexpr SlotType const default_pool_size = 1024;

FixedSizePool(SlotType const in_pool_size = default_pool_size);
FixedSizePool(SlotType const in_pool_size = default_pool_size, int64_t num_bytes_t);

virtual ~FixedSizePool();

Expand Down

0 comments on commit 1c2647c

Please sign in to comment.