本文整理汇总了C++中MemoryMappedFile::testCloseCopyOnWriteView方法的典型用法代码示例。如果您正苦于以下问题:C++ MemoryMappedFile::testCloseCopyOnWriteView方法的具体用法?C++ MemoryMappedFile::testCloseCopyOnWriteView怎么用?C++ MemoryMappedFile::testCloseCopyOnWriteView使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemoryMappedFile
的用法示例。
在下文中一共展示了MemoryMappedFile::testCloseCopyOnWriteView方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void run() {
string fn = "/tmp/testfile.map";
boost::filesystem::remove(fn);
MemoryMappedFile f;
char *p = (char *) f.create(fn, 1024 * 1024 * 1024, true);
verify(p);
strcpy(p, "hello");
{
void *x = f.testGetCopyOnWriteView();
Timer tt;
for( int i = 11; i < 1000000000; i++ )
p[i] = 'z';
cout << "fill 1GB time: " << tt.millis() << "ms" << endl;
f.testCloseCopyOnWriteView(x);
}
/* test a lot of view/unviews */
{
Timer t;
char *q;
for( int i = 0; i < 1000; i++ ) {
q = (char *) f.testGetCopyOnWriteView();
verify( q );
if( i == 999 ) {
strcpy(q+2, "there");
}
f.testCloseCopyOnWriteView(q);
}
cout << "view unview: " << t.millis() << "ms" << endl;
}
f.flush(true);
/* plain old mmaped writes */
{
Timer t;
for( int i = 0; i < 10; i++ ) {
memset(p+100, 'c', 200 * 1024 * 1024);
}
cout << "traditional writes: " << t.millis() << "ms" << endl;
}
f.flush(true);
/* test doing some writes */
{
Timer t;
char *q = (char *) f.testGetCopyOnWriteView();
for( int i = 0; i < 10; i++ ) {
verify( q );
memset(q+100, 'c', 200 * 1024 * 1024);
}
f.testCloseCopyOnWriteView(q);
cout << "inc style some writes: " << t.millis() << "ms" << endl;
}
/* test doing some writes */
{
Timer t;
for( int i = 0; i < 10; i++ ) {
char *q = (char *) f.testGetCopyOnWriteView();
verify( q );
memset(q+100, 'c', 200 * 1024 * 1024);
f.testCloseCopyOnWriteView(q);
}
cout << "some writes: " << t.millis() << "ms" << endl;
}
/* more granular */
{
Timer t;
for( int i = 0; i < 100; i++ ) {
char *q = (char *) f.testGetCopyOnWriteView();
verify( q );
memset(q+100, 'c', 20 * 1024 * 1024);
f.testCloseCopyOnWriteView(q);
}
cout << "more granular some writes: " << t.millis() << "ms" << endl;
}
p[10] = 0;
cout << p << endl;
}