2008-06-06 15:43:15 +02:00
|
|
|
// mmap.h
|
|
|
|
|
2008-07-20 23:37:33 +02:00
|
|
|
/**
|
|
|
|
* Copyright (C) 2008 10gen Inc.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class MemoryMappedFile {
|
|
|
|
public:
|
2008-06-26 21:30:54 +02:00
|
|
|
static void closeAllFiles();
|
2008-06-06 15:43:15 +02:00
|
|
|
MemoryMappedFile();
|
2008-06-26 21:30:54 +02:00
|
|
|
~MemoryMappedFile(); /* closes the file if open */
|
|
|
|
void close();
|
2008-06-06 15:43:15 +02:00
|
|
|
|
|
|
|
/* only smart enough right now to deal with files of a fixed length.
|
|
|
|
creates if DNE
|
|
|
|
*/
|
|
|
|
void* map(const char *filename, int length);
|
|
|
|
|
|
|
|
void flush(bool sync);
|
|
|
|
|
2008-06-30 04:33:59 +02:00
|
|
|
void* viewOfs() { return view; }
|
|
|
|
|
2008-06-06 15:43:15 +02:00
|
|
|
private:
|
|
|
|
HANDLE fd;
|
|
|
|
HANDLE maphandle;
|
|
|
|
void *view;
|
|
|
|
int len;
|
|
|
|
};
|