tahoma2d/toonz/sources/include/tbigmemorymanager.h

70 lines
1.7 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef _TBIGMEMORYMANAGER_
#define _TBIGMEMORYMANAGER_
class Chunkinfo;
#undef DVAPI
#undef DVVAR
#ifdef TSYSTEM_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
#include "tcommon.h"
#include "tthreadmessage.h"
class TRaster;
2016-06-15 18:43:10 +12:00
class DVAPI TBigMemoryManager {
TThread::Mutex m_mutex;
UCHAR *m_theMemory;
std::map<UCHAR *, Chunkinfo> m_chunks;
UCHAR *allocate(UINT &size);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TUINT32 m_availableMemory, m_allocatedMemory;
std::map<UCHAR *, Chunkinfo>::iterator shiftBlock(
const std::map<UCHAR *, Chunkinfo>::iterator &it, TUINT32 offset);
TRaster *findRaster(TRaster *ras);
void checkConsistency();
UCHAR *remap(TUINT32 RequestedSize);
void printLog(TUINT32 size);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TBigMemoryManager();
~TBigMemoryManager();
bool init(TUINT32 sizeinKb);
bool putRaster(TRaster *ras, bool canPutOnDisk = true);
bool releaseRaster(TRaster *ras);
void lock(UCHAR *buffer);
void unlock(UCHAR *buffer);
UCHAR *getBuffer(UINT size);
static TBigMemoryManager *instance();
bool isActive() const { return m_theMemory != 0; }
// void releaseSubraster(UCHAR *chunk, TRaster*subRas);
TUINT32 getAvailableMemoryinKb() const {
assert(m_theMemory != 0);
return m_availableMemory >> 10;
}
void getRasterInfo(int &rasterCount, TUINT32 &totRasterMemInKb,
int &notCachedRasterCount,
TUINT32 &notCachedRasterMemInKb);
2016-03-19 06:57:51 +13:00
#ifdef _DEBUG
2016-06-15 18:43:10 +12:00
TUINT32 m_totRasterMemInKb;
void printMap();
2016-03-19 06:57:51 +13:00
#endif
2016-06-15 18:43:10 +12:00
int getAllocationPeak();
int getAllocationMean();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setRunOutOfContiguousMemoryHandler(void (*callback)(unsigned long size));
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
friend class TRaster;
void (*m_runOutCallback)(unsigned long);
2016-03-19 06:57:51 +13:00
};
#endif