diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-07-02 03:59:18 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-07-02 03:59:18 +0000 |
| commit | 5dd63ff5b888f8d861aa2327507fcefa7103ffeb (patch) | |
| tree | 4c29a551749b18f5233f6c09a5cd3064ca132b52 /Graphics | |
| parent | Reworked Open/SaveFileDialog to allow specifying dialog flags (diff) | |
| download | DiligentCore-5dd63ff5b888f8d861aa2327507fcefa7103ffeb.tar.gz DiligentCore-5dd63ff5b888f8d861aa2327507fcefa7103ffeb.zip | |
VariableSizeAllocationsManager: added Extend method
Diffstat (limited to 'Graphics')
| -rw-r--r-- | Graphics/GraphicsAccessories/interface/VariableSizeAllocationsManager.hpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Graphics/GraphicsAccessories/interface/VariableSizeAllocationsManager.hpp b/Graphics/GraphicsAccessories/interface/VariableSizeAllocationsManager.hpp index c1fc083f..0788db23 100644 --- a/Graphics/GraphicsAccessories/interface/VariableSizeAllocationsManager.hpp +++ b/Graphics/GraphicsAccessories/interface/VariableSizeAllocationsManager.hpp @@ -175,6 +175,12 @@ public: return UnalignedOffset != InvalidAllocation().UnalignedOffset; } + bool operator==(const Allocation& rhs) const + { + return UnalignedOffset == rhs.UnalignedOffset && + Size == rhs.Size; + } + OffsetType UnalignedOffset = InvalidOffset; OffsetType Size = 0; }; @@ -357,6 +363,40 @@ public: return m_FreeBlocksByOffset.size(); } + void Extend(size_t ExtraSize) + { + size_t NewBlockOffset = m_MaxSize; + size_t NewBlockSize = ExtraSize; + + if (!m_FreeBlocksByOffset.empty()) + { + auto LastBlockIt = m_FreeBlocksByOffset.end(); + --LastBlockIt; + + const auto LastBlockOffset = LastBlockIt->first; + const auto LastBlockSize = LastBlockIt->second.Size; + if (LastBlockOffset + LastBlockSize == m_MaxSize) + { + // Extend the last block + NewBlockOffset = LastBlockOffset; + NewBlockSize += LastBlockSize; + + VERIFY_EXPR(LastBlockIt->second.OrderBySizeIt->first == LastBlockOffset); + m_FreeBlocksBySize.erase(LastBlockIt->second.OrderBySizeIt); + m_FreeBlocksByOffset.erase(LastBlockIt); + } + } + + AddNewBlock(NewBlockOffset, NewBlockSize); + + m_MaxSize += ExtraSize; + m_FreeSize += ExtraSize; + +#ifdef DILIGENT_DEBUG + DbgVerifyList(); +#endif + } + private: void AddNewBlock(OffsetType Offset, OffsetType Size) { |
