diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-10-29 14:50:15 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-29 14:50:15 -0400 |
| commit | 066bc37f34ab4f72edef2b71fab50b45c3bb627e (patch) | |
| tree | 6880c04996a7c2b964983d6a006e77a55a75fcde /source/core/slang-memory-arena.cpp | |
| parent | c27b7d91aaf6bc764807a8998a9c885e57c22a1b (diff) | |
Feature/riff improvements (#1099)
* Added RiffReadHelper
* Move type to fourCC in Chunk simplifies some code.
* Make MemoryArena able to track external blocks.
Allow ownership of Data to vary.
Changed IR serialization to use moved allocations to avoid copies.
As it turns out all of the array writes could use unowned data, but doing so requires the IRData to stay in scope longer than IRSerialData, which it does at the moment - but perhaps needs better naming or a control for the feature.
Diffstat (limited to 'source/core/slang-memory-arena.cpp')
| -rw-r--r-- | source/core/slang-memory-arena.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/source/core/slang-memory-arena.cpp b/source/core/slang-memory-arena.cpp index a9fc1ec19..6fc6c0c3f 100644 --- a/source/core/slang-memory-arena.cpp +++ b/source/core/slang-memory-arena.cpp @@ -258,6 +258,42 @@ MemoryArena::Block* MemoryArena::_newBlock(size_t allocSize, size_t alignment) return block; } +void MemoryArena::addExternalBlock(void* inData, size_t size) +{ + // Allocate block + Block* block = (Block*)m_blockFreeList.allocate(); + if (!block) + { + return; + } + + uint8_t* alloc = (uint8_t*)inData; + + const size_t alignMask = m_blockAlignment - 1; + + // Do the alignment on the allocation + uint8_t* const start = (uint8_t*)((size_t(alloc) + alignMask) & ~alignMask); + + // Setup the block + block->m_alloc = alloc; + block->m_start = start; + block->m_end = alloc + size; + block->m_next = nullptr; + + // We don't want to place at start, if there is any used blocks - as that is the one + // that is being split from and can be rewound. So we place just behind in that case + if (m_usedBlocks) + { + block->m_next = m_usedBlocks->m_next; + m_usedBlocks->m_next = block; + } + else + { + // There aren't any blocks, so just place at the front + m_usedBlocks = block; + } +} + void* MemoryArena::_allocateAlignedFromNewBlockAndZero(size_t sizeInBytes, size_t alignment) { void* mem = _allocateAlignedFromNewBlock(sizeInBytes, alignment); |
