Skip to content

Commit d05ba95

Browse files
committed
Changes to allocators talked over with Matt
1 parent 5a86bd3 commit d05ba95

File tree

3 files changed

+15
-32
lines changed

3 files changed

+15
-32
lines changed

include/nbl/core/alloc/IteratablePoolAddressAllocator.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,20 @@ class IteratablePoolAddressAllocator : protected PoolAddressAllocator<_size_type
4646
IteratablePoolAddressAllocator(void* reservedSpc, _size_type addressOffsetToApply, _size_type alignOffsetNeeded, _size_type maxAllocatableAlignment, _size_type bufSz, _size_type blockSz) noexcept :
4747
Base(reservedSpc,addressOffsetToApply,alignOffsetNeeded,maxAllocatableAlignment,bufSz,blockSz) {}
4848

49+
4950
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator
5051
template<typename... Args>
51-
IteratablePoolAddressAllocator(_size_type newBuffSz, IteratablePoolAddressAllocator&& other, Args&&... args) noexcept :
52-
Base(newBuffSz,std::move(other),std::forward<Args>(args)...)
52+
IteratablePoolAddressAllocator(_size_type newBuffSz, const IteratablePoolAddressAllocator& other, Args&&... args) noexcept :
53+
Base(newBuffSz, other, std::forward<Args>(args)...)
5354
{
54-
copyState(other, newBuffSz);
55+
copySupplementaryState(other, newBuffSz);
5556
}
56-
57+
5758
template<typename... Args>
58-
IteratablePoolAddressAllocator(_size_type newBuffSz, const IteratablePoolAddressAllocator& other, Args&&... args) noexcept :
59-
Base(newBuffSz,other,std::forward<Args>(args)...)
59+
IteratablePoolAddressAllocator(_size_type newBuffSz, IteratablePoolAddressAllocator&& other, Args&&... args) noexcept :
60+
IteratablePoolAddressAllocator(newBuffSz,other,std::forward<Args>(args)...)
6061
{
61-
copyState(other, newBuffSz);
62+
Base::operator=(std::move(other));
6263
}
6364

6465
IteratablePoolAddressAllocator& operator=(IteratablePoolAddressAllocator&& other)

include/nbl/core/alloc/PoolAddressAllocator.h

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,6 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
4343
}
4444
}
4545

46-
void copyStateMove(_size_type otherBlockCount, _size_type otherFreeStackCtr, _size_type newBuffSz)
47-
{
48-
if (blockCount > otherBlockCount)
49-
freeStackCtr = blockCount - otherBlockCount;
50-
51-
#ifdef _NBL_DEBUG
52-
assert(Base::checkResize(newBuffSz, Base::alignOffset));
53-
#endif // _NBL_DEBUG
54-
55-
for (_size_type i = 0u; i < freeStackCtr; i++)
56-
getFreeStack(i) = (blockCount - 1u - i) * blockSize + Base::combinedOffset;
57-
58-
for (_size_type i = 0; i < otherFreeStackCtr; i++)
59-
{
60-
_size_type freeEntry = getFreeStack(i) - Base::combinedOffset;
61-
// check in case of shrink
62-
if (freeEntry < blockCount * blockSize)
63-
getFreeStack(freeStackCtr++) = freeEntry + Base::combinedOffset;
64-
}
65-
}
66-
6746
inline bool safe_shrink_size_common(_size_type& sizeBound, _size_type newBuffAlignmentWeCanGuarantee) noexcept
6847
{
6948
_size_type capacity = get_total_size()-Base::alignOffset;
@@ -101,10 +80,13 @@ class PoolAddressAllocator : public AddressAllocatorBase<PoolAddressAllocator<_s
10180
//! When resizing we require that the copying of data buffer has already been handled by the user of the address allocator
10281
template<typename... Args>
10382
PoolAddressAllocator(_size_type newBuffSz, PoolAddressAllocator&& other, Args&&... args) noexcept :
104-
Base(std::move(other),std::forward<Args>(args)...),
83+
Base(other,std::forward<Args>(args)...),
10584
blockCount((newBuffSz-Base::alignOffset)/other.blockSize), blockSize(other.blockSize), freeStackCtr(0u)
10685
{
107-
copyStateMove(other.blockCount, other.freeStackCtr, newBuffSz);
86+
copyState(other, newBuffSz);
87+
88+
Base::operator=(std::move(other));
89+
std::swap(reservedSpace, other.reservedSpace);
10890

10991
other.blockCount = invalid_address;
11092
other.blockSize = invalid_address;

include/nbl/core/containers/DoublyLinkedList.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class DoublyLinkedList
198198
// Copy memory over to new buffer
199199
memcpy(newArray, m_array, m_cap * sizeof(node_t));
200200
// Create new address allocator from old one
201-
m_addressAllocator = std::unique_ptr<address_allocator_t>(new address_allocator_t(newCapacity, std::move(*(m_addressAllocator)), newReservedSpace));
201+
m_addressAllocator = std::make_unique<address_allocator_t>(newCapacity, std::move(*(m_addressAllocator)), newReservedSpace);
202202
// After address allocator creation we can free the old buffer
203203
_NBL_ALIGNED_FREE(m_reservedSpace);
204204
m_cap = newCapacity;
@@ -216,7 +216,7 @@ class DoublyLinkedList
216216
m_reservedSpace = _NBL_ALIGNED_MALLOC(firstPart + capacity * sizeof(node_t), alignof(node_t));
217217
m_array = reinterpret_cast<node_t*>(reinterpret_cast<uint8_t*>(m_reservedSpace) + firstPart);
218218

219-
m_addressAllocator = std::unique_ptr<address_allocator_t>(new address_allocator_t(m_reservedSpace, 0u, 0u, 1u, capacity, 1u));
219+
m_addressAllocator = std::make_unique<address_allocator_t>(m_reservedSpace, 0u, 0u, 1u, capacity, 1u);
220220
m_cap = capacity;
221221
m_back = invalid_iterator;
222222
m_begin = invalid_iterator;

0 commit comments

Comments
 (0)