jjzjj

virtual-memory

全部标签

c++ - boost iostream : how to turn ifstream into memory mapped file?

我想要的是简单地打开文件作为内存映射文件进行读取-以便将来以更快的速度访问它(例如:我们打开文件读取它结束,等待并一次又一次地读取它)同时我希望该文件可以被其他程序修改,当他们修改它时,我希望我的ifstream也能修改。如何使用boostiostreams(或boostinterprocess)做这样的事情?我们可以只是tallos-嘿,这个文件应该为所有应用程序进行内存映射?所以我尝试这样的代码:#include#include#includeusingnamespaceboost::iostreams;intmain(intargc,char**argv){streamout;t

c++ - 简单代码导致错误读取变量: Cannot access memory at address

我正在尝试使用支持python的gdbMinGW-builds.我遇到了一个错误。这是一个相当简单的代码,在MSVC下调试时它工作正常。D:\CppProject\c1\bin\Debug>gdbc1.exeGNUgdb(GDB)7.6(copyright,license,bugreport,etcomittedhere)ReadingsymbolsfromD:\CppProject\c1\bin\Debug\c1.exe...done.(gdb)l1#include2#include34usingnamespacestd;56intmain()7{8vectorv;9v.push_b

c++ - 海湾合作委员会 : C++11 inline object initialization (using "this") does not work when there is a virtual inheritance in hierarchy

当在初始化中使用此指针并且在层次结构中存在虚拟继承时,C++11内联对象初始化不起作用(在GCC中)。这可能是GCC的错误吗(因为它在CLang中工作)?还是C++11标准本身的差距?示例(可以在here中尝试),当使用GCC编译以下代码时:FieldIndexm_inB{"inB",this};不会被执行。但它会在使用CLang编译时执行。变通方法:从FieldIndexContainer派生A作为虚拟#include#include#includeusingnamespacestd;classFieldIndexContainer{public:classFieldIndex{pu

c++ - mmap如何分配超过20Gb?

我尝试使用mmap函数在虚拟空间中分配大量内存。我的需求是大约30Gb,但它不能。我尝试使用20Gb,结果相同。我在具有60GbRAM的OVH64位机器服务器上执行了我的测试。我的测试代码:#include#include#include#includeintmain(){void*r=NULL;printf("%lu\n",sizeof(size_t));r=mmap(NULL,((size_t)20)*1024*1024*1024,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);printf("%d%s\n",r==MAP_

C++ 原子 : would function call act as memory barrier?

我正在阅读这篇文章MemoryOrderingatCompileTime从中说:Infact,themajorityoffunctioncallsactascompilerbarriers,whethertheycontaintheirowncompilerbarrierornot.Thisexcludesinlinefunctions,functionsdeclaredwiththepureattribute,andcaseswherelink-timecodegenerationisused.Otherthanthosecases,acalltoanexternalfunction

c++ - memory_order_seq_cst 如何与非原子操作同步?

如果使用单个原子变量和std::memory_order_seq_cst,是否保证非原子操作不会被重新排序?例如,如果我有std::atomicquux={false};voidfoo(){bar();quux.store(true,std::memory_order_seq_cst);moo();}是bar()保证在调用store之后不会重新排序,并且moo()在调用之前不会重新排序store,只要我使用std::memory_order_seq_cst,至少从另一个线程的角度来看?或者,换句话说,如果从另一个线程运行,以下假设是否有效?if(quux.load(std::memor

c++ - 使用 protected 非虚拟析构函数时抑制 delete-non-virtual-dtor 警告

我有一个纯抽象接口(interface)类和一个实现该接口(interface)的派生类。structFoo{virtualvoiddoStuff()=0;};structBar:Foo{voiddoStuff()override{}};我的接口(interface)类没有虚拟析构函数。因此,尝试使用基类指针破坏派生实例显然是未定义的行为intmain(){Foo*f=newBar;f->doStuff();deletef;}幸运的是我的编译器足够聪明,可以捕捉到这个(使用-Werror)main.cc:15:9:error:deletingobjectofabstractclasst

c++ - 如何解决 : undefined reference to `non-virtual thunk to ...`

我正在尝试弄清楚如何进一步解决此问题。我还想知道如何安装更新版本的ld(如果有意义的话)。所有涉及的包管理器都告诉我,我是最新的。代码在ubuntu12.04和12.10上使用g++(4.7.2)编译、链接和运行,但在FC17上编译失败并出现此错误。ArchiveServiceLib/debug-posix/libArchiveLib.a(NamedIflTiffCache.o):(.rodata._ZTV26UnlockingGenericFileHandle[_ZTV26UnlockingGenericFileHandle]+0x58):undefinedreferenceto`I

C++ : noexcept (or throw()) virtual destructor = default;

下面的代码是合法的吗?classC{virtual~C()noexcept=default;};或classC{virtual~C()throw()=default;};(throw()已弃用,但我的编译器不支持noexcept;;) 最佳答案 8.4.2[dcl.fct.def.default]Anexplicitly-defaultedfunction[...]mayhaveanexplicitexception-specificationonlyifitiscompatible(15.4)withtheexception-spe

c++ - std::atomic::compare_exchange 与两个 memory_order 参数一起使用的真实示例

您能否给出一个真实世界的例子,其中出于某种原因使用了std::atomic::compare_exchange的两个memory_order参数版本(因此一个memory_order参数版本是不够的)? 最佳答案 在许多情况下,compare_exchange上的第二个内存排序参数设置为memory_order_relaxed。在这些情况下,省略它通常并没有错,只是可能效率较低。这里是一个简单的无锁列表/堆栈示例,它需要compare_exchange_weak上的第二个不同的排序参数,以便避免数据竞争。调用push可以并发执行,但