我发现他们有一个键和多个值是唯一的.
#pragma pack(L1_CACHE_LINE)
struct A {
//...
};
#pragma pack()
A a;
Run Code Online (Sandbox Code Playgroud)
和
struct A {
//...
};
A a __attritube__((aligned(L1_CACHE_LINE)))
Run Code Online (Sandbox Code Playgroud)
他们之间有什么区别?
例如:通用设备模块的Makefile
obj-m:=jc.o
default:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
$(MAKE) -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules clean
Run Code Online (Sandbox Code Playgroud)
我考虑是否可以将CFLAGS设置为该文件.当我将默认部分更改为
$(MAKE) -O2 -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
Run Code Online (Sandbox Code Playgroud)
但它没有用.
有帮助吗?非常感谢.
我正在使用boost.pool,但我不知道何时使用boost::pool<>::malloc
和boost::pool<>::ordered_malloc
?
所以,
什么是boost::pool<>::malloc
和boost::pool<>::ordered_malloc
?的区别?
我应该什么时候使用boost::pool<>::ordered_malloc
?
在我的项目中,我包含了pfring.h,但编译错误:net/if.h和linux/if.h中的一些函数是重新定义的.我发现pfring.h包含linux/if.h所以,我测试一个程序,我的测试代码:
#include <linux/if.h>
#include <net/if.h>
int main(void) {
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它预计编译错误.那么,linux/if.h和net/if.h有什么问题?我不能一次包括它们吗?
错误信息:
In file included from test.c:1:0:
/usr/include/linux/if.h:178:19: error: field 'ifru_addr' has incomplete type
/usr/include/linux/if.h:179:19: error: field 'ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:180:19: error: field 'ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:181:19: error: field 'ifru_netmask' has incomplete type
/usr/include/linux/if.h:182:20: error: field 'ifru_hwaddr' has incomplete type
In file included from test.c:2:0:
/usr/include/net/if.h:45:5: error: expected identifier before numeric constant
/usr/include/net/if.h:112:8: error: redefinition of 'struct ifmap'
/usr/include/linux/if.h:136:8: note: originally defined here
/usr/include/net/if.h:127:8: error: redefinition of …
Run Code Online (Sandbox Code Playgroud) 在一些关于算法的文章中,有些使用了这个词lockfree
,有些则使用了lockless
.lockless
和之间有什么区别lockfree
?谢谢!
更新
http://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-dpdk-programmers-guide.pdf
第5.2节 - "Linux*中的无锁环缓冲区",这是使用"无锁"一词的一个例子
比如,它让我困惑:
struct A {
// some fileds...
char buf[SIZE];
};
A a;
a = a;
Run Code Online (Sandbox Code Playgroud)
通过A的字段buf
,看起来默认的赋值操作可能会调用类似于memcpy
将对象X分配给Y的东西,所以如果将对象分配给自身并且没有定义明确的赋值操作,a = a;
如上所述.
memcpy手册页:
DESCRIPTION
The memcpy() function copies n bytes from memory area src to memory area dest. The memory areas must not overlap. Use memmove(3) if the memory areas do overlap.
Run Code Online (Sandbox Code Playgroud)
如果使用memcpy
,可能会发生一些未定义的行为.
那么,C++对象中的默认赋值操作行为是什么?
我的代码是这样的:
#include <iostream>
#include <signal.h>
#include <cstdlib>
void handler(int) {
std::cout << "will exit..." << std::endl;
exit(0);
}
class A {
public:
A() {std::cout << "constructor" << std::endl;}
~A() {std::cout << "destructor" << std::endl;}
};
int main(void) {
signal(SIGINT, &handler);
A a;
for (;;);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
当我按下Ctrl-C时,它打印出:
constructor
^Cwill exit...
Run Code Online (Sandbox Code Playgroud)
没有打印出"析构函数".那么,我怎样才能干净利落地出境呢?
某些CPU和编译器提供预取指令.例如:GCC文档中的 __builtin_prefetch .虽然GCC的文件中有评论,但它对我来说太短了.
我想知道,在prantice中,我们应该何时使用预取?有一些例子吗?谢谢!
我的简单代码如下:
#include <iostream>
#include <atomic>
#include <memory>
int main(void) {
std::shared_ptr<int> p = std::make_shared<int>(5);
std::cout << std::boolalpha << std::atomic_is_lock_free(&p) << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但编译错误:
a.cpp:在函数'int main()'中:a.cpp:7:60:错误:没有匹配函数用于调用'atomic_is_lock_free(std :: shared_ptr*)'std :: cout << std :: boolalpha < <std :: atomic_is_lock_free(&p)<< std :: endl; ^ a.cpp:7:60:注意:候选人是:在a.cpp中包含的文件中:2:0:/usr/include/c++/4.8.2/atomic:804:5:注意:模板bool std :: atomic_is_lock_free(const std :: atomic <_ITp>*)atomic_is_lock_free(const atomic <_ITp>*__a)noexcept ^ /usr/include/c++/4.8.2/atomic:804:5:注意:模板参数推断/替换失败: a.cpp:7:60:注意:'std :: shared_ptr'不是来自'const std :: atomic <_ITp>'std :: cout << std :: boolalpha << std :: atomic_is_lock_free(&p)< <std :: endl; ^在a.cpp中包含的文件中:2:0:/usr/include/c++/4.8.2/atomic:809:5:注意:模板bool std :: atomic_is_lock_free(const volatile …
c++ ×4
arm ×1
attributes ×1
boost ×1
c++11 ×1
containers ×1
destructor ×1
gcc ×1
key-value ×1
linux ×1
linux-kernel ×1
lock-free ×1
lockless ×1
makefile ×1
map ×1
multimap ×1
performance ×1
pool ×1
prefetch ×1
signals ×1
x86 ×1