m_io_service.post(boost::ref(i));
Run Code Online (Sandbox Code Playgroud)
我在一段代码中有这个调用,底层类型i
肯定是可调用的(因为删除boost :: ref导致传递值,这很好),但是clang告诉我:
/opt/dev_64_swat/proto-rpc2/dependencies/boost/include/boost/asio/handler_invoke_hook.hpp:64:3: error: type 'boost::reference_wrapper<rubble::rpc::TcpFrontEndConnectionInvoker>' does not provide a call operator
Run Code Online (Sandbox Code Playgroud)
我如何通过引用传递,我的对象比异步调用更长,如果我可以通过引用传递它们,它们会更优雅(减少boost :: shared_ptr <..>作为成员).
- 编辑 -
我已经浏览了asio的示例目录,并boost::ref
没有为完成处理程序演示.所以我想我在这里运气不好.有没有理由为什么处理程序没有版本接受ref?
- 编辑2:我的样子(除非你对实施有所怀疑,否则不要去看这个). -
namespace rubble { namespace rpc {
struct InProcessInvoker : public InvokerBase
{
struct notification_object_
{
typedef notification_object_ * ptr;
notification_object_()
{
reset();
}
void reset()
{
ready = false;
}
bool ready;
boost::mutex mutex;
boost::condition_variable cond;
};
InProcessInvoker(BackEnd & b_in)
: b(b_in),
notification_object(new notification_object_())
{
b.connect(m_client_data);
}
~InProcessInvoker()
{
if( m_client_data.unique() …
Run Code Online (Sandbox Code Playgroud) c++ functional-programming pass-by-reference boost-asio boost-ref
template <typename R>
class shared_future
{
...
// move support
shared_future(shared_future && other);
shared_future(unique_future<R> && other);
shared_future& operator=(shared_future && other);
shared_future& operator=(unique_future<R> && other);
...
}
Run Code Online (Sandbox Code Playgroud)
究竟是那些双括号?我浏览了"BS C++ Langauge 3d版"并找不到任何解释.
我有一个使用以下OpenSSL调用的算法:
HMAC_update() / HMAC_final() // ripe160
EVP_CipherUpdate() / EVP_CipherFinal() // cbc_blowfish
Run Code Online (Sandbox Code Playgroud)
这些算法采用了unsigned char *
"纯文本".我的输入数据来自C++ std::string::c_str()
,它源自协议缓冲区对象,作为编码的UTF-8字符串.UTF-8字符串意味着是endian neutrial.然而,我对OpenSSL如何对数据执行操作有点偏执.
我的理解是加密算法适用于8位数据块,如果unsigned char *
在执行操作时a 用于指针算术,算法应该是endian中性的,我不需要担心任何事情.我的不确定性因为我正在使用小端机器并且从未进行任何真正的跨架构编程而更加复杂.
我的信念/推理是基于以下两个属性
c_str()
无论CPU架构如何,生成的ptr都会以相同的方式进行迭代.我知道获得明确答案的最佳方法是使用QEMU并进行一些跨平台的单元测试(我打算这样做).我的问题是要求对我的推理进行评论,或许在面临类似问题时可以帮助其他程序员.
我发现以下模式经常发生:
b->last = ngx_cpymem(b->last, "</pre><hr>", sizeof("</pre><hr>") - 1);
Run Code Online (Sandbox Code Playgroud)
请注意,文字字符串使用了两次.提取物来自nginx源库.
在编译单元中遇到这些文字时,编译器应该能够合并这些文字.
我的问题是:
这些问题很重要,因为它允许程序员在不损失效率的情况下进行冗长 - 即,考虑将大量静态数据模型硬连接到程序中(例如,某些低级方案中使用的决策支持系统的规则) .
编辑
2分/澄清
上面的代码由公认的"主"程序员编写.这家伙一手写了nginx.
我没有问过文字硬编码的哪种可能机制更好.所以不要偏离主题.
编辑2
我最初的例子是非常人为的和限制性的.以下代码段显示了嵌入到内部硬编码知识中的字符串文字的用法.第一个片段用于配置解析器告诉它为哪个字符串设置哪个枚举值,第二个片段通常用作程序中的字符串.我个人对此感到满意,只要编译器使用字符串文字的一个副本,并且由于元素是静态的,它们不会进入全局符号表.
static ngx_conf_bitmask_t ngx_http_gzip_proxied_mask[] = {
{ ngx_string("off"), NGX_HTTP_GZIP_PROXIED_OFF },
{ ngx_string("expired"), NGX_HTTP_GZIP_PROXIED_EXPIRED },
{ ngx_string("no-cache"), NGX_HTTP_GZIP_PROXIED_NO_CACHE },
{ ngx_string("no-store"), NGX_HTTP_GZIP_PROXIED_NO_STORE },
{ ngx_string("private"), NGX_HTTP_GZIP_PROXIED_PRIVATE },
{ ngx_string("no_last_modified"), NGX_HTTP_GZIP_PROXIED_NO_LM },
{ ngx_string("no_etag"), NGX_HTTP_GZIP_PROXIED_NO_ETAG },
{ ngx_string("auth"), NGX_HTTP_GZIP_PROXIED_AUTH },
{ ngx_string("any"), NGX_HTTP_GZIP_PROXIED_ANY },
{ ngx_null_string, 0 }
};
Run Code Online (Sandbox Code Playgroud)
紧随其后:
static ngx_str_t ngx_http_gzip_no_cache = ngx_string("no-cache");
static ngx_str_t ngx_http_gzip_no_store …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个带有C-ABI接口的C++库.
这就是GCC如何处理关于重整的外部"C"限定符:
namespace x {
extern "C" int monkey(int x) {
return 1;
}
int chimpanzee(int x) {
return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
相关nm
产出:
00000000004005cd T _ZN1x10chimpanzeeEi
00000000004005bf T monkey
Run Code Online (Sandbox Code Playgroud)
问题: 我想在命名空间中保留C-ABI中涉及的函数,以便最大程度地重用.重要说明:编译库后,我将为链接器提供映射文件(GCC)或模块定义文件(MSVC).
我有一个构建脚本片段,如下所示:
foreach(...)
...
add_custom_command( OUTPUT ${fn_c} ${fn_s} ${fn_p_c} {fn_p_h}
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --proto_path=${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${proto_var} --cpp_out=. --plugin=protoc-gen-RBLRPC=${CMAKE_BINARY_DIR}/tools/protoc-gen-RBLRPC --RBLRPC_out=.
DEPENDS ${proto_var}
)
if(${M_S_} OR ${M_C_})
set(MARSHALL_RPC_FILES ${MARSHALL_RPC_FILES} ${fn_p_c})
message(status "copy marshall -------------------")
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/${fn_c}
${CMAKE_CURRENT_BINARY_DIR}/${fn_s}
${CMAKE_CURRENT_BINARY_DIR}/${fn_p_h} DESTINATION ${CMAKE_SOURCE_DIR}/include/rpc/marshall)
endif()
...
endforeach(...)
Run Code Online (Sandbox Code Playgroud)
在执行自定义命令的情况下,不会生成复制的文件,但是cmake会在首次通过脚本时尝试复制文件.我欢迎任何解决这个问题的建议,而不会大幅改变我的写作.
编译器:linux上的clang ++ x86-64.
已经有一段时间了,因为我编写了任何复杂的低级系统代码,并且我对系统原语(windows和pthreads/posix)进行了编程.所以,#s和out的内容已经从我的记忆中消失了.我正在boost::asio
和boost::thread
目前一起工作.
为了模拟针对异步函数执行器的同步RPC(在请求被编辑的地方boost::io_service
有多个线程),我正在使用boost同步原语.为了好奇,我决定使用这些原语.这就是我所看到的.io::service::run
io_serviced::post
sizeof
struct notification_object
{
bool ready;
boost::mutex m;
boost::condition_variable v;
};
...
std::cout << sizeof(bool) << std::endl;
std::cout << sizeof(boost::mutex) << std::endl;
std::cout << sizeof(boost::condition_variable) << std::endl;
std::cout << sizeof(notification_object) << std::endl;
...
Run Code Online (Sandbox Code Playgroud)
输出:
1
40
88
136
Run Code Online (Sandbox Code Playgroud)
互斥锁的四十个字节?? ?? ?WTF!88为条件_变量!!! 请记住,我被这个体积臃肿击退,因为我想,可能造成上百的应用程序notification_object
的
这种便携性开销似乎很荒谬,有人可以证明这一点吗?据我所知,这些原语应该是4或8字节宽,具体取决于CPU的内存模型.
c++ boost-thread micro-optimization boost-asio systems-programming
这不编译,
#include <boost/intrusive_ptr.hpp>
class X
{
public:
void intrusive_ptr_add_ref(X* blah)
{
}
void intrusive_ptr_release(X * blah)
{
}
};
int main()
{
boost::intrusive_ptr<X> ex(new X);
}
Run Code Online (Sandbox Code Playgroud)
但这样做:
#include <boost/intrusive_ptr.hpp>
class X
{
public:
friend void intrusive_ptr_add_ref(X* blah)
{
}
friend void intrusive_ptr_release(X * blah)
{
}
};
int main()
{
boost::intrusive_ptr<X> ex(new X);
}
Run Code Online (Sandbox Code Playgroud)
还有这个 :
#include <boost/intrusive_ptr.hpp>
class X
{
public:
};
void intrusive_ptr_add_ref(X* blah)
{
}
void intrusive_ptr_release(X * blah)
{
}
int main()
{
boost::intrusive_ptr<X> ex(new X); …
Run Code Online (Sandbox Code Playgroud) 注意:如果您知道任何(非精细的)库代码可以实现我想要的功能,请启发C/C++程序员,我会接受它作为答案.
我有一个全局变量设置为以下类的实例.它的目的是允许我设置一些手动中断点,printf
在scrapy蜘蛛中放置一些快速和脏的样式调试点(我特别需要在满足某些条件时调整解析器,有一些非常罕见的输入数据异常) -改编自这个.
Os是OS X 10.8.
import termios, fcntl, sys, os
class DebugWaitKeypress(object):
def __init__(self):
self.fd = sys.stdin.fileno()
self.oldterm = termios.tcgetattr(self.fd)
self.newattr = termios.tcgetattr(self.fd)
self.newattr[3] = self.newattr[3] & ~termios.ICANON & ~termios.ECHO
termios.tcsetattr(self.fd, termios.TCSANOW, self.newattr)
self.oldflags = fcntl.fcntl(self.fd, fcntl.F_GETFL)
fcntl.fcntl(self.fd, fcntl.F_SETFL, self.oldflags | os.O_NONBLOCK)
def wait(self):
sys.stdin.read(1)
def __del__(self):
print "called del"
termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.oldterm)
fcntl.fcntl(self.fd, fcntl.F_SETFL, self.oldflags)
Run Code Online (Sandbox Code Playgroud)
当我按下Ctrl-C并且进程正在展开时,我得到以下异常:
Exception AttributeError: "'NoneType' object has no attribute 'tcsetattr'" in <bound method DebugWaitKeypress.__del__ of <hon.spiders.custom_debug.DebugWaitKeypress object at 0x108985e50>> ignored …
Run Code Online (Sandbox Code Playgroud) 我创建了一个标准的c ++库项目,我试图包含<tuple>
但它似乎没有作为顶级标题包含在内,而是我还需要包含它<tr1/tuple>
.llvm编译器方言设置为-std=c++11
.
我是否正确假设即使xcode 4.4具有符合c ++ 11标准的编译器,它还没有附带符合C++ 11标准的库?
这个问题可能与此一个.
c++ ×9
boost-asio ×2
boost-thread ×2
portability ×2
abi ×1
algorithm ×1
boost-ref ×1
c ×1
c++11 ×1
cmake ×1
encryption ×1
endianness ×1
include-path ×1
oop ×1
posix ×1
python ×1
scrapy ×1
xcode ×1