草庐IT

memory_compiler

全部标签

c++ - 为什么 memory_order_relaxed 在 x86 上使用原子(锁前缀)指令?

在VisualC++2013上,当我编译以下代码时#includeintmain(){std::atomicv(2);returnv.fetch_add(1,std::memory_order_relaxed);}我在x86上取回了以下程序集:51pushecxB802000000moveax,28D0C24leaecx,[esp]8701xchgeax,dwordptr[ecx]B801000000moveax,1F00FC101lockxadddwordptr[ecx],eax59popecxC3ret在x64上类似:B802000000moveax,287442408xchgea

c++ - SFINAE : Detecting if a function is called by a compile time known value

我喜欢在我的一个ctors以编译时已知值被调用时做一些检查。有办法检测吗?所以当有人调用它时:Aa(10);因为10是编译时已知常量,所以我喜欢调用一个特殊的构造函数,如下所示:template>A(intValue){}知道如何解决这个问题吗?谢谢! 最佳答案 积分常量可以解决您的问题:structA{template*=nullptr>A(std::integral_constant){}};然后,你可以像这样使用它:Aa{std:integral_constant{}};为了便于使用,您还可以使用类似于boost::hana的

c++ - C1001 : An internal error has occurred in the compiler

这应该是不言自明的。我正在尝试实现分布排序,但MSVC编译器崩溃了。这似乎是用我的SFINAE检测成员函数的特定情况,如果我不将indexert传递给函数,或者替换has_get_index,这似乎不会发生。如果我删除剩余的索引器重载中的任何一个,它也不会发生。如果sortable有一个getIndex()const成员,问题仍然存在。1>test.cpp(34):fatalerrorC1001:Aninternalerrorhasoccurredinthecompiler.1>(compilerfile'msc1.cpp',line1420)1>Toworkaroundthispro

c++ - CMake + 库达 : compile cpp files in Cuda-mode (--x=cu)

假设我有一个文件,我们称它为foo.cpp,我的目标是在cuda模式下用nvcc编译这个文件。在命令行中,这可以通过调用轻松完成:nvcc--x=cufoo.cpp我正在苦苦挣扎的是让CMake做同样的事情。事实证明,CMake命令cuda_add_executable(foofoo.cpp)将过滤*.cpp文件并使用c++编译器(而不是nvcc)。请注意,将所有文件重命名为*.cu不是一种选择,因为代码库还必须支持非cuda构建。 最佳答案 在FindCUDAsourcecode我找到了一个选项来为特定的非.cu文件激活CUDA编

c++ - VC++ 使用 fp :fast causes wrong (not just inaccurate) results - is this a compiler bug?

我已经安装了最新的VS2017更新(15.4.4),但在编译我们的项目时,单元测试开始失败。在使用优化(/O2)和浮点快速模型(/fp:fast)时,问题似乎发生在某些情况下。以前的编译器(VS2017update15.2)没有出现这个问题。这是一个示例程序:#includeconstfloatFACTOR=0.01745329251994329576923690768489f;unsignedlonglonghoursToMicrosecs(inthours){returnhours*3600*1000000LL;}floatdegToRad(floatdeg){returndeg*

c# - C#<->C++ DLLImport "Attempted to read or write protected memory."问题

我有一个C++dll,其中有一个函数,我试图从C#应用程序调用。这是C++头文件中的代码extern"C"_declspec(dllexport)intLabelStoringSSDsim(intdevNum,UCHARserial[40],UCHARwwn[40],UCHARConfigID[5],UCHARFrmRev[8],UCHARDevName[40],inteCode);这是C++源文件中的代码intLabelStoringSSDsim(intdevNum,UCHARserialLbl[40],UCHARwwnLbl[40],UCHARConfigID[5],UCHARFr

c++ - 用于取消标志的 std::atomic_bool:std::memory_order_relaxed 是正确的内存顺序吗?

我有一个从套接字读取并生成数据的线程。每次操作后,线程都会检查一个std::atomic_bool标志以确定它是否必须提前退出。为了取消操作,我将取消标志设置为true,然后在工作线程对象上调用join()。线程和取消函数的代码如下所示:std::threadwork_thread;std::atomic_boolcancel_requested{false};voidthread_func(){while(!cancel_requested.load(std::memory_order_relaxed))process_next_element();}voidcancel(){can

c++ - 将指针转换为模板参数 : Comeau & MSVC compile, GCC 失败

考虑以下代码:templateclassbase{};intmain(){basetest;return0;}Comeau和MSVC都可以毫无问题地编译它(除了Comeau警告未使用的变量),而GCC在basetest;上失败行,说明Infunction`intmain()':acaststoatypeotherthananintegralorenumerationtypecannotappearinaconstant-expressiontemplateargument1isinvalid它到底在提示什么?谁是对的——这段代码应该编译吗?值得注意的是,我的GCC版本非常旧(3.4.2

c++ - Opencv 错误 : no GPU support (library is compiled without CUDA support)

我正在尝试使用CUDA在GPU上使用opencv处理一些图像处理任务。我正在使用ubuntu。我毫无问题地设置了我的两个产品Opencv和Cuda,我确信这一点。但是,当我尝试在eclipse中运行sampleCOde时,出现错误:OpenCV错误:在mallocPitch中没有GPU支持(库在没有CUDA支持的情况下编译),文件/home/muad/Source/OpenCV-2.4.2/modules/core/src/gpumat.cpp,第749行我重做了我的opencv,但我还是明白了。 最佳答案 如文档中所述,您必须使用

c++ - 如何避免 "unable to read memory"

我有一个结构:structa{a(){};a(intone,inttwo):a(one),b(two){};inta;intb;intc;}a*b;coutc;有时当我想读取(例如)c并且在debbuger中这个值被称为'unabletoreadmemory'然后我的程序崩溃了。现在,如何检查该值是否可读?最好的问候。 最佳答案 你还没有初始化指向任何东西的指针,所以它是无效的。通常,您无法测试指针是否指向有效对象。由您来确保它确实如此;例如:aobj(1,2);//anobjecta*b=&obj;//apointer,point