diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2019-11-08 09:13:44 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-08 09:13:44 -0500 |
| commit | 0ac010a72e777b2c284583fcb8554abee83d8ff5 (patch) | |
| tree | 7133e5c3117c180d19ce11841187ff3f9d2ec5fe /source/core/slang-memory-arena.h | |
| parent | 99c295477fa1f6c5ce47e0d1c8fb3eea9d5e5f98 (diff) | |
Riff Container Stream Writing (#1116)
* * Added option to get random bytes from RandomGenerator
* Added ability to allocate only in current block on MemoryArena
* Allowed RiffContainer to not allocate new Data blocks, if can just extend the Data it has (because it's at the end of current block and there is space for the new data).
* Added coverage for change on Riff unit test
* Add test coverage for allocations over multiple Data blocks.
* Improve comment on riff unit tests.
Diffstat (limited to 'source/core/slang-memory-arena.h')
| -rw-r--r-- | source/core/slang-memory-arena.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/source/core/slang-memory-arena.h b/source/core/slang-memory-arena.h index d346197f0..f63a48413 100644 --- a/source/core/slang-memory-arena.h +++ b/source/core/slang-memory-arena.h @@ -84,6 +84,11 @@ public: @return The allocation (or nullptr if unable to allocate). */ void* allocateUnaligned(size_t sizeInBytes); + /** Allocate some aligned memory of at least size bytes, without alignment, and only from current block. + @param sizeInBytes Size of allocation wanted. + @return The allocation (or nullptr if unable to allocate in current block). */ + void* allocateCurrentUnaligned(size_t sizeInBytes); + /** Allocates a null terminated string. NOTE, it is not possible to rewind to a zero length string allocation (because such a strings memory is not held on the arena) @@ -127,6 +132,9 @@ public: /// Gets the block alignment that is passed at initialization otherwise 0 an invalid block alignment. size_t getBlockAlignment() const { return m_blockAlignment; } + /// Get the default block payload size + size_t getBlockPayloadSize() const { return m_blockPayloadSize; } + /// Estimate of total amount of memory used in bytes. The number can never be smaller than actual used memory but may be larger size_t calcTotalMemoryUsed() const; /// Total memory allocated in bytes @@ -241,6 +249,23 @@ SLANG_FORCE_INLINE void* MemoryArena::allocateUnaligned(size_t sizeInBytes) } // -------------------------------------------------------------------------- +SLANG_FORCE_INLINE void* MemoryArena::allocateCurrentUnaligned(size_t sizeInBytes) +{ + // Align with the minimum alignment + uint8_t* mem = m_current; + uint8_t* end = mem + sizeInBytes; + if (end <= m_end) + { + m_current = end; + return mem; + } + else + { + return nullptr; + } +} + +// -------------------------------------------------------------------------- SLANG_FORCE_INLINE void* MemoryArena::allocate(size_t sizeInBytes) { assert(sizeInBytes > 0); |
