我有一个包含大约20个文件夹的repo,当我从SVN转换为Git时创建.是否可以从Git存储库(在Bitbucket上)签出单个文件夹?或者我必须将每个文件夹作为单独的回购?
我想要的是当一个消息队列接收到一个 int N 时,处理函数将在 N 秒后被调用。下面是我的代码。
如果两个近消息队列的持续时间秒数大于 int N,则运行正常,但是当两个接收到的消息队列之间的持续时间秒数小于 N 时,处理程序将在一个处理程序中打印“操作已取消”,这不是我想要的想。
如果您有任何帮助,我将不胜感激。
#include <boost/asio.hpp>
#include <zmq.h>
#include <boost/thread.hpp>
#include <iostream>
boost::asio::io_service io_service;
void* context = zmq_ctx_new();
void* sock_pull = zmq_socket(context, ZMQ_PULL);
void handler(const boost::system::error_code &ec) {
std::cout << "hello, world" << "\t" << ec.message() << std::endl;
}
void run() {
io_service.run();
}
void thread_listener() {
int nRecv;
boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(0));
while( true ) {
zmq_recv(sock_pull, &nRecv, sizeof(nRecv), 0);
std::cout << nRecv << std::endl;
timer.expires_from_now(boost::posix_time::seconds(nRecv));
timer.async_wait(handler);
}
}
int main(int argc, …Run Code Online (Sandbox Code Playgroud) 这是我用来在共享内存上分配映射的一段代码,我使用的是 boost::interprocess 和托管共享内存段,现在的问题是我遇到了内存泄漏。下面给出的是顶部输出。
顶部输出:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1. 27594 tpmon 20 0 46132 2140 1664 S 0.0 0.0 0:00.00 test_stub
2. 27594 tpmon 20 0 46132 2176 1664 S 0.0 0.0 0:00.01 test_stub
3. 27594 tpmon 20 0 46264 2248 1664 S 0.0 0.0 0:00.01 test_stub
4. 27594 tpmon 20 0 46264 2280 1664 S 0.0 0.0 0:00.01 test_stub
Run Code Online (Sandbox Code Playgroud)
从顶部输出可以明显看出常驻内存在不断增加,在共享内存映射中,我只有下面列出的条目,作为三元组:
Deb0 0 150520 DEB1 1 150520 Deb10 10 150520 Deb11 11 …
我需要将(boost :: asio::) streambuf的内容复制到std :: string.
以下代码有效,但我认为_msg和临时std :: string之间存在不必要的副本:
Msg (boost::asio::streambuf & sb, size_t bytes_transferred) :
_nBytesInMsg (bytes_transferred)
{
boost::asio::streambuf::const_buffers_type buf = sb.data();
_msg = std::string(
boost::asio::buffers_begin(buf),
boost::asio::buffers_begin(buf) + _nBytesInMsg);
}
Run Code Online (Sandbox Code Playgroud)
我尝试用以下内容替换:
_msg.reserve(_nBytesInMsg);
std::copy(
boost::asio::buffers_begin(buf),
boost::asio::buffers_begin(buf) + _nBytesInMsg,
_msg.begin()
);
Run Code Online (Sandbox Code Playgroud)
在编译时,它不会将任何内容复制到_msg字符串.
编译器(gcc4.4.7)会优化这种情况 - 例如将streambuf直接复制到_msg而不使用临时的吗?
是否有一个迭代器,我可以使用boost :: asio :: streambuf :: const_buffers_type,以使std :: copy工作?
我有以下代码:
qstn:
cout << "Input customer's lastname: ";
getline(cin, lname);
if (lname.find_first_not_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ") != string::npos) {
cout << "You can only input alpha here!\n";
cin.clear();
goto qstn;
} else if (lname.empty()) {
cout << "Please enter your firstname!\n";
cin.clear();
goto qstn;
}
int lnamel = lname.length();
int strl = str.length();
int is = 0;
for (int i = 1; i < strl;) {
i++;
is++;
if (lname[i] == lname[is] && lname[i] == ' ' || lname[0] == ' ') { …Run Code Online (Sandbox Code Playgroud) 正如我在一些关于 rust 的视频中看到的那样,它有这样的东西(我使用 c++ 而不是 rust 来展示想法):
template<typename T>
class Synchronized {
public:
Synchronized(T);
Something<T> get();
private:
std::mutex lock_;
};
Run Code Online (Sandbox Code Playgroud)
和这样的用法:
Synchronized<std::string> obj;
auto s = obj.get();
//after that you can work with s as with std::string
//and obj.lock_ in locked state, after s was destroyed
//obj.lock_ will be unlocked
Run Code Online (Sandbox Code Playgroud)
是boost或其他一些C ++通俗图书馆都有这样的模式实现?
我尝试使用qi::uint_parser<int>()。但这是一样的qi::uint_。它们都匹配从0到的整数std::numeric_limits<unsigned int>::max()。
被qi::uint_parser<int>()设计成这个样子?我应该使用什么解析器来匹配从0到的整数范围std::numeric_limits<int>::max()?谢谢。
(从Spirit-general邮件列表中解除的问题)
你好,
我正在使用精神气的解析器.语法运行良好,但是我有一些问题用Semantic Actions填充我的struct实例.
使用直接结构属性,如"Request.id"和"Request.url",代码正常工作.但我不知道如何填充嵌套结构"Info"中的属性,也不知道如何在"Request.list"中推送值.
这是我的代码(要解析的字符串可以包含任何顺序的值):
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <iostream>
#include <vector>
#include <string>
struct Request
{
std::string id;
std::string url;
std::vector<std::string> list;
struct Info
{
std::string id;
std::string desc;
};
Info info;
};
BOOST_FUSION_ADAPT_STRUCT(
Request,
(std::string, id)
)
template <typename Iterator>
struct request_parser : boost::spirit::qi::grammar<Iterator, Request(), boost::spirit::ascii::space_type>
{
request_parser() : request_parser::base_type(start)
{
using namespace boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phx = boost::phoenix;
quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
start …Run Code Online (Sandbox Code Playgroud) 下面的代码旨在执行以下操作:我有一个包含boost asio的解析器对象.解析器对象包含io服务和worker,因此io服务运行函数永远不会返回.只要解析器对象处于活动状态,就可以进行异步请求.当解析器对象超出范围并且队列中仍有请求时,我想完成所有并且解析器对象被销毁.
在这种情况下,根本没有调用处理程序,我不知道为什么.我认为共享指针和一些依赖循环可能存在问题.运行valgrind报告"可能会丢失内存".
任何想法如何使这个工作,所以解析器对象保持活着,直到所有工作完成?
#include <boost/asio.hpp>
#include <memory>
#include <thread>
#include <functional>
#include <string>
#include <iostream>
struct Resolver : public std::enable_shared_from_this<Resolver> {
boost::asio::io_service io_service;
std::unique_ptr<boost::asio::io_service::work> work;
std::unique_ptr<std::thread> iothread;
struct Query : public std::enable_shared_from_this<Query>{
std::shared_ptr<Resolver> service;
boost::asio::ip::tcp::resolver resolver;
boost::asio::ip::tcp::resolver::query query;
std::function<void(boost::asio::ip::tcp::resolver::iterator &)> handler;
Query(std::shared_ptr<Resolver> res, std::function<void(boost::asio::ip::tcp::resolver::iterator &)> handler, const std::string &name) : resolver(res->io_service), query(name, ""), handler(handler) {
service = res;
}
void start() {
auto self = shared_from_this();
resolver.async_resolve(query, [self](const boost::system::error_code& ec, boost::asio::ip::tcp::resolver::iterator iterator){
self->handler(iterator);
});
}
};
Resolver() …Run Code Online (Sandbox Code Playgroud) 我正在学习内存池,并尝试boost::pool_allocator在我的项目中使用。根据文档,我做了一个关于时间成本的小测试:
template <typename Alloc>
void test()
{
using namespace std::chrono;
auto t0 = high_resolution_clock::now();
for (int i = 0; i < 1000; ++i) {
std::vector<int, Alloc> vec;
for (int j = 0; j < 10000; ++j)
vec.push_back(i + j);
}
auto t1 = high_resolution_clock::now();
auto time_ms = duration<double>(t1 - t0).count() * 1e3;
cout << "time cost: " << time_ms << " ms" << endl;
}
int main()
{
test<std::allocator<int>>();
test<boost::pool_allocator<int>>();
}
Run Code Online (Sandbox Code Playgroud)
结果是:
time cost: 3.97602 ms …Run Code Online (Sandbox Code Playgroud) c++ ×9
boost ×5
boost-asio ×3
c++11 ×3
boost-spirit ×2
parsing ×2
bitbucket ×1
boost-pool ×1
git ×1
goto ×1
iostream ×1
istream ×1
memory ×1
numeric ×1
valgrind ×1
validation ×1
zeromq ×1