Added code to determine how much memory a volume is using.
Also map of homogenous regions is no longer static.
This commit is contained in:
parent
cacde3e01a
commit
5eb538e925
@ -51,6 +51,7 @@ namespace PolyVox
|
||||
|
||||
void fill(VoxelType tValue);
|
||||
bool isHomogeneous(void);
|
||||
uint32_t sizeInChars(void);
|
||||
|
||||
private:
|
||||
uint16_t m_uSideLength;
|
||||
|
@ -169,5 +169,19 @@ namespace PolyVox
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename VoxelType>
|
||||
uint32_t Block<VoxelType>::sizeInChars(void)
|
||||
{
|
||||
uint32_t uSizeInChars = sizeof(Block<VoxelType>);
|
||||
|
||||
if(m_tData != 0)
|
||||
{
|
||||
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
|
||||
uSizeInChars += uNoOfVoxels * sizeof(VoxelType);
|
||||
}
|
||||
|
||||
return uSizeInChars;
|
||||
}
|
||||
#pragma endregion
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ namespace PolyVox
|
||||
/// to check for and remove duplicate homogeneous regions whenever you have spare
|
||||
/// processing time.
|
||||
///
|
||||
/// -# Copying a volume naturally means that all the voxels in the second voluem are
|
||||
/// -# Copying a volume naturally means that all the voxels in the second volume are
|
||||
/// the same as the first. Therefore volume copying is a relatively fast operation in
|
||||
/// which all the blocks in the second volume simply reference the first volume. Future
|
||||
/// modifications to either volume will, of course, cause the blocks to become unshared.
|
||||
@ -111,7 +111,7 @@ namespace PolyVox
|
||||
|
||||
public:
|
||||
///Constructor
|
||||
Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 64);
|
||||
Volume(uint16_t uWidth, uint16_t uHeight, uint16_t uDepth, uint16_t uBlockSideLength = 32);
|
||||
///Destructor
|
||||
~Volume();
|
||||
|
||||
@ -136,9 +136,11 @@ namespace PolyVox
|
||||
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
|
||||
|
||||
void tidyUpMemory(uint32_t uNoOfBlocksToProcess = (std::numeric_limits<uint32_t>::max)());
|
||||
///Calculates roughly how much memory is used by the volume.
|
||||
uint32_t calculateSizeInChars(void);
|
||||
|
||||
private:
|
||||
POLYVOX_SHARED_PTR< Block<VoxelType> > getHomogenousBlock(VoxelType tHomogenousValue) const;
|
||||
POLYVOX_SHARED_PTR< Block<VoxelType> > getHomogenousBlock(VoxelType tHomogenousValue);
|
||||
|
||||
std::vector< POLYVOX_SHARED_PTR< Block<VoxelType> > > m_pBlocks;
|
||||
std::vector<bool> m_vecBlockIsPotentiallyHomogenous;
|
||||
@ -148,8 +150,7 @@ namespace PolyVox
|
||||
//shared. A call to shared_ptr::unique() from within setVoxel was not sufficient as weak_ptr's did
|
||||
//not contribute to the reference count. Instead we store shared_ptr's here, and check if they
|
||||
//are used by anyone else (i.e are non-unique) when we tidy the volume.
|
||||
//FIXME - How do we handle sharing between two volumes with different block sizes?!
|
||||
static std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > > m_pHomogenousBlock;
|
||||
std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > > m_pHomogenousBlock;
|
||||
|
||||
uint32_t m_uNoOfBlocksInVolume;
|
||||
|
||||
@ -177,10 +178,6 @@ namespace PolyVox
|
||||
uint32_t m_uCurrentBlockForTidying;
|
||||
};
|
||||
|
||||
//Required for the static member
|
||||
template <class VoxelType> std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > > Volume<VoxelType>::m_pHomogenousBlock;
|
||||
|
||||
|
||||
//Some handy typedefs
|
||||
typedef Volume<float> FloatVolume;
|
||||
typedef Volume<uint8_t> UInt8Volume;
|
||||
|
@ -353,11 +353,52 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// The returned value is not precise because it is hard to say how much memory
|
||||
/// STL vectors and maps take iternally, but it accounts for all the block data
|
||||
/// which is by far the most significant contributer. The returned value is in
|
||||
/// multiples of the basic type 'char', which is equal to a byte on most systems.
|
||||
/// Important Note: The value returned by this function is only correct if there
|
||||
/// is only one volume in memory. This is because blocks are shared between volumes
|
||||
/// without any one volume being the real owner.
|
||||
/// \return The amount of memory used by the volume.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
template <typename VoxelType>
|
||||
uint32_t Volume<VoxelType>::calculateSizeInChars(void)
|
||||
{
|
||||
//The easy part
|
||||
uint32_t uSize = sizeof(Volume<VoxelType>);
|
||||
|
||||
//Now determine the size of the non homogenous data.
|
||||
for(uint32_t ct = 0; ct < m_pBlocks.size(); ct++)
|
||||
{
|
||||
if(m_pBlocks[ct].unique()) //Check for non-homogenity
|
||||
{
|
||||
uSize += sizeof(POLYVOX_SHARED_PTR< Block<VoxelType> >); //The pointer
|
||||
uSize += m_pBlocks[ct]->sizeInChars(); //The data it points to.
|
||||
}
|
||||
}
|
||||
|
||||
//The size of the m_vecBlockIsPotentiallyHomogenous vector
|
||||
uSize += m_vecBlockIsPotentiallyHomogenous.size() * sizeof(bool);
|
||||
|
||||
//Now determine the size of the homogenous data.
|
||||
//We could just get the number of blocks in the map and multiply
|
||||
//by the block size, but it feels safer to do it 'properly'.
|
||||
for(std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > >::const_iterator iter = m_pHomogenousBlock.begin(); iter != m_pHomogenousBlock.end(); iter++)
|
||||
{
|
||||
uSize += sizeof(POLYVOX_SHARED_PTR< Block<VoxelType> >); //The pointer
|
||||
uSize += iter->second->sizeInChars(); //The data it points to.
|
||||
}
|
||||
|
||||
return uSize;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Private Implementation
|
||||
template <typename VoxelType>
|
||||
POLYVOX_SHARED_PTR< Block<VoxelType> > Volume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue) const
|
||||
POLYVOX_SHARED_PTR< Block<VoxelType> > Volume<VoxelType>::getHomogenousBlock(VoxelType tHomogenousValue)
|
||||
{
|
||||
typename std::map<VoxelType, POLYVOX_SHARED_PTR< Block<VoxelType> > >::iterator iterResult = m_pHomogenousBlock.find(tHomogenousValue);
|
||||
if(iterResult == m_pHomogenousBlock.end())
|
||||
|
Loading…
x
Reference in New Issue
Block a user