本文整理汇总了C++中MemoryMappedFile::length方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryMappedFile::length方法的具体用法?C++ MemoryMappedFile::length怎么用?C++ MemoryMappedFile::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryMappedFile
的用法示例。
在下文中一共展示了MemoryMappedFile::length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lk
__declspec(noinline) void makeChunkWritableOld(size_t chunkno) {
scoped_lock lk(mapViewMutex);
if( writable.get(chunkno) )
return;
size_t loc = chunkno * MemoryMappedFile::ChunkSize;
void *Loc = (void*) loc;
size_t ofs;
MongoMMF *mmf = privateViews.find( (void *) (loc), ofs );
MemoryMappedFile *f = (MemoryMappedFile*) mmf;
assert(f);
size_t len = MemoryMappedFile::ChunkSize;
assert( mmf->getView() <= Loc );
if( ofs + len > f->length() ) {
// at the very end of the map
len = (size_t) (f->length() - ofs);
}
else {
;
}
// todo: check this goes away on remap
DWORD old;
bool ok = VirtualProtect(Loc, len, PAGE_WRITECOPY, &old);
if( !ok ) {
DWORD e = GetLastError();
log() << "VirtualProtect failed " << Loc << ' ' << len << ' ' << errnoWithDescription(e) << endl;
assert(false);
}
writable.set(chunkno);
}
示例2: 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;
}