95 template <
class Data_T>
139 template <
class Data_T>
154 boost::mutex::scoped_lock lock_A(
m_mutex);
170 bytesFreed = deallocateBlock<half>(cb);
171 if (bytesFreed > 0) {
176 bytesFreed = deallocateBlock<float>(cb);
177 if (bytesFreed > 0) {
182 bytesFreed = deallocateBlock<double>(cb);
183 if (bytesFreed > 0) {
188 bytesFreed = deallocateBlock<V3h>(cb);
189 if (bytesFreed > 0) {
194 bytesFreed = deallocateBlock<V3f>(cb);
195 if (bytesFreed > 0) {
200 bytesFreed = deallocateBlock<V3d>(cb);
201 if (bytesFreed > 0) {
217 boost::mutex::scoped_lock lock(
m_mutex);
225 deallocateBlock<half>(it);
228 deallocateBlock<float>(it);
231 deallocateBlock<double>(it);
234 deallocateBlock<V3h>(it);
237 deallocateBlock<V3f>(it);
240 deallocateBlock<V3d>(it);
253 int fileId,
int blockIdx)
287 long long int numLoads = 0;
320 long long int numBlocks = 0;
353 long long int numBlocks = 0;
#define FIELD3D_NAMESPACE_HEADER_CLOSE
long long totalLoads()
Returns the total number of block loads in the cache.
void resetCacheStatistics()
Resets block load.
int deallocateBlock(const SparseFile::CacheBlock &cb)
Utility function to attempt to deallocate a single block and advance the "hand".
CacheList m_blockCacheList
List of dynamically loaded blocks to be considered for unloading when the cache is full...
int blockSize(int blockIdx) const
Returns the number of bytes used by the data in the block.
float cacheEfficiency()
Computes the efficiency, the ratio of the number of blocks ever loaded to the number of loads...
int m_memUse
Current amount of memory in use in bytes.
std::vector< bool > blockUsed
Flags of whether the blocks have been accessed since they were last considered for deallocation by th...
void deallocateBlocks(int bytesNeeded)
Utility function to reclaim the specified number of bytes by deallocating unneeded blocks...
Reference< Data_T > & ref(int idx)
Returns a reference to the index. This is specialized so that the correct data member is accessed...
long long totalLoadedBlocks()
Returns the total number of blocks loaded (max 1 per block) into cache.
int m_maxMemUseInBytes
Max amount om memory to use in bytes.
std::vector< int > refCounts
Per-block counts of the number of current references to the blocks. If a block's ref count is non-zer...
float m_maxMemUse
Max amount om memory to use in megabytes.
FIELD3D_NAMESPACE_OPEN typedef::half half
boost::mutex m_mutex
Mutex to prevent multiple threads from deallocating blocks at the same time.
bool m_limitMemUse
Whether to limit memory use of sparse fields from disk. Enables the cache and dynamic loading when tr...
static SparseFileManager * ms_singleton
Pointer to singleton.
void setLimitMemUse(bool enabled)
Sets whether to limit memory usage and do dynamic loading for sparse fields.
float cacheFractionLoaded()
Computes the ratio of blocks in the cache to the total number of blocks that have been loaded (includ...
long long numLoadedBlocks()
Returns the total number of blocks currently loaded into cache.
CacheList::iterator m_nextBlock
Pointer to the next block to test for unloading in the cache, the "hand" of the clock.
void unloadBlock(int blockIdx)
Unloads the block with the given index from memory.
SparseFile::FileReferences m_fileData
Vector containing information for each of the managed fields. The order matches the index stored in e...
SparseFile::Reference< Data_T > & reference(int index)
Returns a reference to the Reference object with the given index.
int numRefs() const
Returns the number of file references of the corresponding collection.
void addBlockToCache(DataTypeEnum blockType, int fileId, int blockIdx)
Adds the newly loaded block to the cache, managed by the paging algorithm.
SparseFileManager()
Private to prevent instantiation.
bool doLimitMemUse() const
Returns whether to limit memory usage and do dynamic loading for sparse fields.
void flushCache()
Flushes the entire block cache for all files, should probably only be used for debugging.
float cacheLoadsPerBlock()
Computes the overall loaded-blocks-to-load ratio for cached files.
Contains the SparseField class.
static SparseFileManager & singleton()
Returns a reference to the singleton instance.
void setMaxMemUse(float maxMemUse)
Sets the maximum memory usage, in MB, by dynamically loaded sparse fields.
boost::mutex * blockMutex
Allocated array of mutexes, one per block, to lock each block individually, for guaranteeing thread-s...