Skip to content

Commit

Permalink
Changed unique_ptr<> to shared_ptr<>
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield committed May 17, 2023
1 parent e196a9d commit 5688f3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions include/vsg/core/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ namespace vsg
Allocator* parent = nullptr;
std::string name;
size_t blockSize = 0;
std::map<void*, std::unique_ptr<MemoryBlock>> memoryBlocks;
MemoryBlock* latestMemoryBlock = nullptr;
std::map<void*, std::shared_ptr<MemoryBlock>> memoryBlocks;
std::shared_ptr<MemoryBlock> latestMemoryBlock;

MemoryBlocks(Allocator* in_parent, const std::string& in_name, size_t in_blockSize);
virtual ~MemoryBlocks();
Expand Down
8 changes: 4 additions & 4 deletions src/vsg/core/Allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ void* Allocator::MemoryBlocks::allocate(std::size_t size)
for (auto itr = memoryBlocks.rbegin(); itr != memoryBlocks.rend(); ++itr)
{
auto& block = itr->second;
if (block.get() != latestMemoryBlock)
if (block != latestMemoryBlock)
{
auto ptr = block->allocate(size);
if (ptr) return ptr;
Expand All @@ -390,8 +390,8 @@ void* Allocator::MemoryBlocks::allocate(std::size_t size)

size_t new_blockSize = std::max(size, blockSize);

std::unique_ptr<MemoryBlock> block(new MemoryBlock(new_blockSize, parent->memoryTracking, parent->memoryBlocksAllocatorType));
latestMemoryBlock = block.get();
auto block = std::make_shared<MemoryBlock>(new_blockSize, parent->memoryTracking, parent->memoryBlocksAllocatorType);
latestMemoryBlock = block;

auto ptr = block->allocate(size);

Expand Down Expand Up @@ -455,7 +455,7 @@ size_t Allocator::MemoryBlocks::deleteEmptyMemoryBlocks()
{
info(" MemoryBlocks:deleteEmptyMemoryBlocks() MemoryBlocks.name = ", name, ", removing MemoryBlock", block.get());
}
if (block.get() == latestMemoryBlock) latestMemoryBlock = nullptr;
if (block == latestMemoryBlock) latestMemoryBlock = nullptr;
memoryDeleted += block->memorySlots.totalMemorySize();
itr = memoryBlocks.erase(itr);
}
Expand Down

0 comments on commit 5688f3b

Please sign in to comment.