summaryrefslogtreecommitdiff
path: root/source/utilities/MemMappedFile.h
blob: 8cc63f55ace0e2ebfc83f5fb6ea1d6a624f60511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/
#ifndef _MEMMAPPEDFILE_H_
#define _MEMMAPPEDFILE_H_

#include "t_basicdefinitions.h"
#include <string>

#ifdef _WIN32
#include <windows.h>
#endif

class MemMappedFile
{
public:
    MemMappedFile(uint32 alignmentLength = 512);
    ~MemMappedFile();

    uint8 *AllocateFileData(uint64 offset, uint64 size);
    void ReleaseFileData(uint8 *data, uint64 offset, uint64 size);
    uint64 GetFileSize();
    int LoadFileData(const char *path);
    int GetError();
private:
    std::string path_;
    uint64 size_;
    bool isMapped_;
    uint32 alignmentLength_;
    uint8 *mappedData_;
    int error_;
#ifdef _WIN32
    HANDLE handle_;
    HANDLE memmap_;
#else
    int descriptor_;
#endif
};

#endif // _MEMMAPPEDFILE_H_