本文整理汇总了C++中MemoryMappedFile::map方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryMappedFile::map方法的具体用法?C++ MemoryMappedFile::map怎么用?C++ MemoryMappedFile::map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryMappedFile
的用法示例。
在下文中一共展示了MemoryMappedFile::map方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processDiagLog
void processDiagLog( const char * file ) {
Connection c;
MemoryMappedFile f;
long length;
unsigned long long L = 0;
char * root = (char*)f.map( file , L, MemoryMappedFile::SEQUENTIAL );
verify( L < 0x80000000 );
length = (long) L;
verify( root );
verify( length > 0 );
char * pos = root;
long read = 0;
while ( read < length ) {
Message m(pos,false);
int len = m.header()->len;
DbMessage d(m);
cout << len << " " << d.getns() << endl;
processMessage( c , m );
read += len;
pos += len;
}
f.close();
}
示例2: lsnThread
/** remember "last sequence number" to speed recoveries */
void lsnThread() {
Client::initThread("lsn");
time_t last = 0;
while( 1 ) {
unsigned long long lsn = j.toStoreLastSeqNum.take();
// if you are on a really fast fsync interval, we don't write this as often
if( time(0) - last < 5 )
continue;
last = time(0);
try {
// os can flush as it likes. if it flushes slowly, we will just do extra work on recovery.
// however, given we actually close the file, that seems unlikely.
MemoryMappedFile f;
unsigned long long length = 8;
unsigned long long *L = static_cast<unsigned long long*>(f.map(lsnPath().string().c_str(), length));
assert(L);
*L = lsn;
}
catch(std::exception& e) {
log() << "write to lsn file fails " << e.what() << endl;
}
}
}
示例3: journalReadLSN
unsigned long long journalReadLSN() {
try {
// os can flush as it likes. if it flushes slowly, we will just do extra work on recovery.
// however, given we actually close the file, that seems unlikely.
MemoryMappedFile f;
unsigned long long *L = static_cast<unsigned long long*>(f.map(lsnPath().string().c_str()));
assert(L);
return *L;
}
catch(std::exception& e) {
log() << "couldn't read journal/lsn file - if a recovery is needed will apply all files. " << e.what() << endl;
}
return 0;
}
示例4: out
int test2_old9() {
out() << "test2" << endl;
printStackTrace();
if ( 1 )
return 1;
MemoryMappedFile f;
long len = 64*1024*1024;
char *p = (char *) f.map("/tmp/test.dat", len);
char *start = p;
char *end = p + 64*1024*1024-2;
end[1] = 'z';
int i;
while ( p < end ) {
*p++ = ' ';
if ( ++i%64 == 0 ) {
*p++ = '\n';
*p++ = 'x';
}
}
*p = 'a';
f.flush(true);
out() << "done" << endl;
char *x = start + 32 * 1024 * 1024;
char *y = start + 48 * 1024 * 1024;
char *z = start + 62 * 1024 * 1024;
strcpy(z, "zfoo");
out() << "y" << endl;
strcpy(y, "yfoo");
strcpy(x, "xfoo");
strcpy(start, "xfoo");
dbexit( EXIT_TEST );
return 1;
}
示例5: drillDown
void drillDown( path root ) {
if ( is_directory( root ) ) {
directory_iterator end;
directory_iterator i(root);
while ( i != end ) {
path p = *i;
drillDown( p );
i++;
}
return;
}
if ( ! ( endsWith( root.string().c_str() , ".bson" ) ||
endsWith( root.string().c_str() , ".bin" ) ) ) {
cerr << "don't know what to do with [" << root.string() << "]" << endl;
return;
}
out() << root.string() << endl;
string ns;
{
string dir = root.branch_path().string();
if ( dir.find( "/" ) == string::npos )
ns += dir;
else
ns += dir.substr( dir.find_last_of( "/" ) + 1 );
}
{
string l = root.leaf();
l = l.substr( 0 , l.find_last_of( "." ) );
ns += "." + l;
}
if ( boost::filesystem::file_size( root ) == 0 ) {
out() << "file " + root.native_file_string() + " empty, aborting" << endl;
return;
}
out() << "\t going into namespace [" << ns << "]" << endl;
MemoryMappedFile mmf;
assert( mmf.map( root.string().c_str() ) );
char * data = (char*)mmf.viewOfs();
int read = 0;
int num = 0;
while ( read < mmf.length() ) {
BSONObj o( data );
conn().insert( ns.c_str() , o );
read += o.objsize();
data += o.objsize();
if ( ! ( ++num % 1000 ) )
out() << "read " << read << "/" << mmf.length() << " bytes so far. " << num << " objects" << endl;
}
out() << "\t " << num << " objects" << endl;
}