用Windows的文件映射机制,实现大批量数据的快速存储(2)
基于文件镜像的快速大容量数据存储类。该类使用Windows下的 CreateFileMapping() 函数实现,不支持其它系统。
该类中的文件镜像原理可以参考:http://www.juntuan.net/hkbc/winbc/n/2006-04-19/14320.html
当要读取或写入的数据跨多个MapView的时候,该类会自动处理MapView的切换。
*/
class enstFileCache : public QObject
{
Q_OBJECT
public:
/*!
construct the class.
*/
enstFileCache();
/*!
destruct the class.
*/
~enstFileCache();
/*!
打开镜像文件。
@return 当打开镜像文件失败时返回false,比如磁盘空间不够。
*/
bool CreateFileCache(const QString &pFileName);
/*!
向镜像文件中追加数据。
*/
bool AppendData(T_INT8* pData, int pDataLength);
/*!
从镜像文件的指定位置读取数据。
*/
bool ReadData(T_INT64 pAddressOffset, T_INT8* pData, int pDataLength);
protected:
void DumpWindowsErrorMessage();
private:
T_INT64 mMappingViewSize;
HANDLE mFileHandle;
HANDLE mMappingHandle;
T_INT64 mWriteMappingOffset;
LPVOID mWriteBuffer;
T_INT64 mWriteBufferOffset;
T_INT64 mReadMappingOffset;
LPVOID mReadBuffer;
};
#endif //enstfilecache_h
- 上一篇:vc中如何使用设备描述表
- 下一篇:Visual C#程序员面试基础问题和答案