【问题标题】:recursive boost::xpressive using too much memory递归 boost::xpressive 使用太多内存
【发布时间】:2018-11-11 02:19:40
【问题描述】:

嗨 boost::xpressive 用户,

我在尝试使用 boost::xpressive 解析某些决策树时遇到堆栈溢出错误。它似乎适用于达到一定大小的树,但在“大”树上失败,“大”似乎意味着大约 3000 个节点,而 gdb 的堆栈深度为 133979 帧。我想我需要以某种方式优化正则表达式,但没有 .* 任何地方,所以我不知道从这里去哪里。

#include <boost/regex.hpp>
#include <boost/xpressive/xpressive.hpp>
#include <boost/xpressive/regex_actions.hpp>

using namespace boost::xpressive;
using namespace regex_constants;


sregex integral_number;
sregex floating_point_number;

sregex bid;
sregex ask;
sregex side;
sregex value_on_market_limit_ratio_gt;
sregex value_on_market_delta_ratio_gt;

sregex stdevs_from_mean_auction_time_gt;
sregex no_orders_on_opposite_side;
sregex is_pushing_price;
sregex is_desired;

sregex predicate, leaf, branch, tree;

integral_number = sregex_compiler().compile("[-+]?[0-9]+");
floating_point_number = sregex_compiler().compile("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?");
stdevs_from_mean_auction_time_gt = "StdevsFromMeanAuctionTimeGT(" >> floating_point_number >> ")";
side = sregex_compiler().compile("def::BID|def::ASK");
value_on_market_limit_ratio_gt = "ValueOnMarketLimitRatioGT<" >> side >> ">(" >> floating_point_number >> ")";
value_on_market_delta_ratio_gt = "ValueOnMarketDeltaRatioGT(" >> floating_point_number >> ")";
no_orders_on_opposite_side = sregex_compiler().compile("NoOrdersOnOppositeSide");
is_pushing_price = sregex_compiler().compile("IsPushingPrice");
is_desired = sregex_compiler().compile("IsDesired");
predicate = value_on_market_limit_ratio_gt | value_on_market_delta_ratio_gt | stdevs_from_mean_auction_time_gt | no_orders_on_opposite_side | is_pushing_price | is_desired;
leaf = sregex_compiler().compile("SEARCH_TO_MAX|AMEND_TO_AVAILABLE|AMEND_TO_AVAILABLE_MINUS_RECENT_ORDER_SIZE|AMEND_TO_CURRENT_MINUS_RECENT_ORDER_SIZE|SEARCH_BY_RECENT_ORDER_SIZE|PULL|DO_NOTHING");
branch = "Branch(" >> predicate >> "," >> by_ref(tree) >> "," >> by_ref(tree) >> ")";
tree = leaf | branch;

smatch what;
regex_match(s, what, tree)

在这里,s 未定义,因为它是一个不适合问题的 75000 个字符的字符串。如何修改这些表达式以使匹配在更小的空间内执行?

【问题讨论】:

    标签: c++ regex boost boost-regex boost-xpressive


    【解决方案1】:

    我找到了解决这个问题的方法,将分支的定义更改为

    branch = "Branch(" >> keep(predicate) >> "," >> keep(by_ref(tree)) >> "," >> keep(by_ref(tree)) >> ")";
    

    为了限制回溯,从而限制内存使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-24
      • 2011-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-04
      相关资源
      最近更新 更多