Skip to content
This repository was archived by the owner on Aug 11, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions utils/vptr/include/virtual_ptr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <queue>
#include <set>
#include <stdexcept>
#include <unordered_map>

namespace cl {
Expand Down Expand Up @@ -267,7 +268,12 @@ class PointerMapper {
/**
* Constructs the PointerMapper structure.
*/
PointerMapper() : m_pointerMap{}, m_freeList{} {};
PointerMapper(base_ptr_t baseAddress = 4096)
: m_pointerMap{}, m_freeList{}, m_baseAddress{baseAddress} {
if (m_baseAddress == 0) {
throw std::invalid_argument(std::string("Base address cannot be zero"));
}
};

/**
* PointerMapper cannot be copied or moved
Expand All @@ -291,7 +297,7 @@ class PointerMapper {
pMapNode_t p{b, bufSize, false};
// If this is the first pointer:
if (m_pointerMap.empty()) {
virtual_pointer_t initialVal{1};
virtual_pointer_t initialVal{m_baseAddress};
m_pointerMap.emplace(initialVal, p);
return initialVal;
}
Expand Down Expand Up @@ -421,6 +427,10 @@ class PointerMapper {
/* List of free nodes available for re-using
*/
std::set<typename pointerMap_t::iterator, SortBySize> m_freeList;

/* Base address used when issuing the first virtual pointer, allows users
* to specify alignment. Cannot be zero. */
size_t m_baseAddress;
};

/**
Expand Down