11 #ifndef __MEMORYMAPPEDFILE_H__
12 #define __MEMORYMAPPEDFILE_H__
21 #include <sys/types.h>
31 template <
class T>
class CMemoryMappedFile :
public CSGObject
37 SG_UNSTABLE(
"CMemoryMappedFile::CMemoryMappedFile()",
72 open_flags=O_RDWR | O_CREAT;
73 mmap_prot=PROT_READ|PROT_WRITE;
74 mmap_flags=MAP_SHARED;
80 mmap_flags=MAP_PRIVATE;
85 fd = open(fname, open_flags, S_IRWXU | S_IRWXG | S_IRWXO);
92 if (lseek(
fd, fsize, SEEK_SET) != fsize || write(
fd, &byte, 1) != 1)
93 SG_ERROR(
"Error creating file of size %ld bytes\n", fsize);
97 if (fstat(
fd, &sb) == -1)
98 SG_ERROR(
"Error determining file size\n");
165 for (uint64_t i=offs; i<
length; i++)
191 void write_line(
const char* line, uint64_t len, uint64_t& offs)
193 char* s = ((
char*)
address) + offs;
195 SG_ERROR(
"Writing beyond size of file\n");
197 for (uint64_t i=0; i<len; i++)
229 for (uint64_t i=0; i<
length; i++)
263 inline virtual const char*
get_name()
const {
return "MemoryMappedFile"; }
virtual ~CMemoryMappedFile()
void write_line(const char *line, uint64_t len, uint64_t &offs)
char * get_line(uint64_t &len, uint64_t &offs)
void set_truncate_size(uint64_t sz=0)
T operator[](uint64_t index) const
virtual const char * get_name() const
T operator[](int32_t index) const
Class SGObject is the base class of all shogun objects.
CMemoryMappedFile(const char *fname, char flag='r', int64_t fsize=0)
uint64_t last_written_byte
#define SG_UNSTABLE(func,...)