From 99390580dd043cf771cfe1179221ea19584e21f0 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 12 Apr 2015 10:35:12 +0200 Subject: [PATCH] Replaced number with constant. --- include/PolyVox/PagedVolume.h | 13 +++++++++---- include/PolyVox/PagedVolume.inl | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/PolyVox/PagedVolume.h b/include/PolyVox/PagedVolume.h index 38db965b..5dc5bf8e 100644 --- a/include/PolyVox/PagedVolume.h +++ b/include/PolyVox/PagedVolume.h @@ -307,10 +307,15 @@ namespace PolyVox uint32_t m_uChunkCountLimit = 0; - // The size of the volume - //Region m_regValidRegionInChunks; - - mutable std::unique_ptr< Chunk > m_arrayChunks[16384]; + // Chunks are stored in the following array which is used as a hash-table. Conventional wisdom is that such a hash-table + // should not be more than half full to avoid conflicts, and a practical chunk size seems to be 64^3. With this configuration + // there can be up to 32768*64^3 = 8 gigavoxels (with each voxel perhaps being many bytes). This should effectively make use + // of even high end machines. Of course, the user can choose to limit the memory usage in which case much less of the chunk + // array will actually be used. None-the-less, we have chosen to use a fixed size array (rather than a vector) as it appear to + // be slightly faster (probably due to the extra pointer indirection in a vector?) and the actual size of this array should + // just be 1Mb or so. + static const uint32_t uChunkArraySize = 65536; + mutable std::unique_ptr< Chunk > m_arrayChunks[uChunkArraySize]; // The size of the chunks uint16_t m_uChunkSideLength; diff --git a/include/PolyVox/PagedVolume.inl b/include/PolyVox/PagedVolume.inl index ab6af57c..8de87ce3 100644 --- a/include/PolyVox/PagedVolume.inl +++ b/include/PolyVox/PagedVolume.inl @@ -58,7 +58,7 @@ namespace PolyVox // Enforce sensible limits on the number of chunks. const uint32_t uMinPracticalNoOfChunks = 32; // Enough to make sure a chunks and it's neighbours can be loaded, with a few to spare. - const uint32_t uMaxPracticalNoOfChunks = 32768; // Should prevent multi-gigabyte volumes when chunk sizes are reasonable. + const uint32_t uMaxPracticalNoOfChunks = uChunkArraySize / 2; // A hash table should only become half-full to avoid too many clashes. POLYVOX_LOG_WARNING_IF(m_uChunkCountLimit < uMinPracticalNoOfChunks, "Requested memory usage limit of " << uTargetMemoryUsageInBytes / (1024 * 1024) << "Mb is too low and cannot be adhered to."); m_uChunkCountLimit = (std::max)(m_uChunkCountLimit, uMinPracticalNoOfChunks); @@ -287,7 +287,7 @@ namespace PolyVox } iIndex++; - iIndex %= 16384; + iIndex %= uChunkArraySize; } while (iIndex != iStartIndex); // Check whether the chunk was found. @@ -307,7 +307,7 @@ namespace PolyVox pChunk->m_uChunkLastAccessed = ++m_uTimestamper; // Important, as we may soon delete the oldest chunk //m_mapChunks.insert(std::make_pair(v3dChunkPos, std::unique_ptr(pChunk))); - for (uint32_t ct = iStartIndex; ct < 16384; ct++) + for (uint32_t ct = iStartIndex; ct < uChunkArraySize; ct++) { if (m_arrayChunks[ct] == nullptr) {