
有人可以帮助我使用msgpack wiki: http://wiki.msgpack.org/pages/viewpage.action?pageId=1081387中的下一个示例(流媒体功能),并提供更多使用此库和流媒体功能的正确示例.
#include <msgpack.hpp> #include <iostream> #include <string> int main(voID) { // serializes multiple objects using msgpack::packer. msgpack::sbuffer buffer; msgpack::packer<msgpack::sbuffer> pk(&buffer); pk.pack(std::string("Log message ... 1")); pk.pack(std::string("Log message ... 2")); pk.pack(std::string("Log message ... 3")); // deserializes these objects using msgpack::unpacker. msgpack::unpacker pac; // Feeds the buffer. pac.reserve_buffer(buffer.size()); memcpy(pac.buffer(),buffer.data(),buffer.size()); pac.buffer_consumed(buffer.size()); // Now starts streaming deserialization. msgpack::unpacked result; while(pac.next(&result)) { std::cout << result.get() << std::endl; } // results: // $g++ stream.cc -lmsgpack -o stream // $./stream // "Log message ... 1" // "Log message ... 2" // "Log message ... 3" } Valgrind说它有下一个错误:
==11325== 1 errors in context 1 of 2:==11325== Mismatched free() / delete / delete []==11325== at 0x48CC919: operator delete(voID*) (vg_replace_malloc.c:387)==11325== by 0x804A623: std::auto_ptr<msgpack::zone>::reset(msgpack::zone*) (auto_ptr.h:242)==11325== by 0x804A2E1: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:229)==11325== by 0x8049E93: main (pack2.cpp:24)==11325== Address 0x6e447c0 is 0 bytes insIDe a block of size 8,220 alloc'd==11325== at 0x48CD876: malloc (vg_replace_malloc.c:236)==11325== by 0x48DABC9: msgpack_zone_new (zone.c:198)==11325== by 0x48D811F: msgpack_unpacker_release_zone (unpack.c:333)==11325== by 0x804A3DA: msgpack::unpacker::release_zone() (unpack.hpp:261)==11325== by 0x804A31C: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:234)==11325== by 0x8049E93: main (pack2.cpp:24)==11325== ==11325== ==11325== 2 errors in context 2 of 2:==11325== Mismatched free() / delete / delete []==11325== at 0x48CC919: operator delete(voID*) (vg_replace_malloc.c:387)==11325== by 0x804A623: std::auto_ptr<msgpack::zone>::reset(msgpack::zone*) (auto_ptr.h:242)==11325== by 0x804A335: msgpack::unpacker::next(msgpack::unpacked*) (unpack.hpp:234)==11325== by 0x8049E93: main (pack2.cpp:24)==11325== Address 0x6e3c5c0 is 0 bytes insIDe a block of size 8,220 alloc'd==11325== at 0x48CD876: malloc (vg_replace_malloc.c:236)==11325== by 0x48DABC9: msgpack_zone_new (zone.c:198)==11325== by 0x48D8211: msgpack_unpacker_init (unpack.c:194)==11325== by 0x804A08D: msgpack::unpacker::unpacker(unsigned int) (unpack.hpp:187)==11325== by 0x8049DC5: main (pack2.cpp:15)解决方法 在这个例子中看起来一切正常.根据valgrind调用跟踪,这个BUG有些在Msgpack库中. 总结
以上是内存溢出为你收集整理的c – MsgPack中的free()/ delete不匹配全部内容,希望文章能够帮你解决c – MsgPack中的free()/ delete不匹配所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)