小编大宝剑*_*大宝剑的帖子


"#pragma pack"和"__attribute __((aligned))"之间的区别是什么?

#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)

他们之间有什么区别?

attributes gcc

22
推荐指数
2
解决办法
2万
查看次数

是否可以将CFLAGS设置为Linux内核模块Makefile?

例如:通用设备模块的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)

但它没有用.

有帮助吗?非常感谢.

makefile linux-device-driver linux-kernel

22
推荐指数
2
解决办法
2万
查看次数

boost :: pool <> :: malloc和boost :: pool <> :: ordered_malloc之间有什么区别,什么时候应该使用boost :: pool <> :: ordered_malloc?

我正在使用boost.pool,但我不知道何时使用boost::pool<>::mallocboost::pool<>::ordered_malloc

所以,

  1. 什么是boost::pool<>::mallocboost::pool<>::ordered_malloc?的区别?

  2. 我应该什么时候使用boost::pool<>::ordered_malloc

boost pool

15
推荐指数
1
解决办法
2056
查看次数

linux/if.h和net/if.h有什么问题?

在我的项目中,我包含了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)

linux

13
推荐指数
2
解决办法
1万
查看次数

无锁和无锁之间有什么区别?

在一些关于算法的文章中,有些使用了这个词lockfree,有些则使用了lockless.lockless和之间有什么区别lockfree?谢谢!

更新

http://www.intel.com/content/dam/www/public/us/en/documents/guides/intel-dpdk-programmers-guide.pdf

第5.2节 - "Linux*中的无锁环缓冲区",这是使用"无锁"一词的一个例子

lock-free lockless

9
推荐指数
1
解决办法
6019
查看次数

什么是c ++的默认分配操作行为?

比如,它让我困惑:

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++对象中的默认赋值操作行为是什么?

c++ assignment-operator

8
推荐指数
1
解决办法
2589
查看次数

如何在c ++中处理中断信号并调用析构函数?

可能重复:
如果发出SIGINT或SIGSTP,是否会调用析构函数?

我的代码是这样的:

#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)

没有打印出"析构函数".那么,我怎样才能干净利落地出境呢?

c++ destructor signals

6
推荐指数
1
解决办法
5676
查看次数

我们什么时候应该使用预取?

某些CPU和编译器提供预取指令.例如:GCC文档中的 __builtin_prefetch .虽然GCC的文件中有评论,但它对我来说太短了.

我想知道,在prantice中,我们应该何时使用预取?有一些例子吗?谢谢!

performance x86 arm prefetch

6
推荐指数
3
解决办法
3357
查看次数

std :: atomic_is_lock_free(shared_ptr <T>*)没有编译

我的简单代码如下:

#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++ c++11

6
推荐指数
0
解决办法
1097
查看次数