Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _TBIGMEMORYMANAGER_
Toshihiro Shimizu 890ddd
#define _TBIGMEMORYMANAGER_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class Chunkinfo;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TSYSTEM_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tcommon.h"
Toshihiro Shimizu 890ddd
#include "tthreadmessage.h"
Toshihiro Shimizu 890ddd
class TRaster;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TBigMemoryManager {
Shinya Kitaoka 120a6e
  TThread::Mutex m_mutex;
Shinya Kitaoka 120a6e
  UCHAR *m_theMemory;
Shinya Kitaoka 120a6e
  std::map<uchar *,="" chunkinfo=""> m_chunks;</uchar>
Shinya Kitaoka 120a6e
  UCHAR *allocate(UINT &size);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TUINT32 m_availableMemory, m_allocatedMemory;
Shinya Kitaoka 120a6e
  std::map<uchar *,="" chunkinfo="">::iterator shiftBlock(</uchar>
Shinya Kitaoka 120a6e
      const std::map<uchar *,="" chunkinfo="">::iterator &it, TUINT32 offset);</uchar>
Shinya Kitaoka 120a6e
  TRaster *findRaster(TRaster *ras);
Shinya Kitaoka 120a6e
  void checkConsistency();
Shinya Kitaoka 120a6e
  UCHAR *remap(TUINT32 RequestedSize);
Shinya Kitaoka 120a6e
  void printLog(TUINT32 size);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TBigMemoryManager();
Shinya Kitaoka 120a6e
  ~TBigMemoryManager();
Shinya Kitaoka 120a6e
  bool init(TUINT32 sizeinKb);
Shinya Kitaoka 120a6e
  bool putRaster(TRaster *ras, bool canPutOnDisk = true);
Shinya Kitaoka 120a6e
  bool releaseRaster(TRaster *ras);
Shinya Kitaoka 120a6e
  void lock(UCHAR *buffer);
Shinya Kitaoka 120a6e
  void unlock(UCHAR *buffer);
Shinya Kitaoka 120a6e
  UCHAR *getBuffer(UINT size);
Shinya Kitaoka 120a6e
  static TBigMemoryManager *instance();
Shinya Kitaoka 120a6e
  bool isActive() const { return m_theMemory != 0; }
Shinya Kitaoka 120a6e
  // void releaseSubraster(UCHAR *chunk, TRaster*subRas);
Shinya Kitaoka 120a6e
  TUINT32 getAvailableMemoryinKb() const {
Shinya Kitaoka 120a6e
    assert(m_theMemory != 0);
Shinya Kitaoka 120a6e
    return m_availableMemory >> 10;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  void getRasterInfo(int &rasterCount, TUINT32 &totRasterMemInKb,
Shinya Kitaoka 120a6e
                     int ¬CachedRasterCount,
Shinya Kitaoka 120a6e
                     TUINT32 ¬CachedRasterMemInKb);
Toshihiro Shimizu 890ddd
#ifdef _DEBUG
Shinya Kitaoka 120a6e
  TUINT32 m_totRasterMemInKb;
Shinya Kitaoka 120a6e
  void printMap();
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  int getAllocationPeak();
Shinya Kitaoka 120a6e
  int getAllocationMean();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  void setRunOutOfContiguousMemoryHandler(void (*callback)(unsigned long size));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Shinya Kitaoka 120a6e
  friend class TRaster;
Shinya Kitaoka 120a6e
  void (*m_runOutCallback)(unsigned long);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif