[boost-spirit qi] internal copies
Hello *,
I think this is more the question to spirit devlopers. I would like to know
how spirit internally maintains the parsed data? Here is an example of what
I mean.
I have to parse some byte sequence represented as hex pairs:
00 ce ab 00 de ad be ef ...
If I use the parser like this:
boost::spirit::qi::uint_parser
data_item;
Are the fields of the map used directly while parsing, or are there some temporaries, which will be first created (somewhere inside qi core) and filled with data and afterwards assigned to the corresponding map field? Many thanks for the gread lib! Ovanes
I think this is more the question to spirit devlopers. I would like to know how spirit internally maintains the parsed data? Here is an example of what I mean. I have to parse some byte sequence represented as hex pairs:
00 ce ab 00 de ad be ef ...
If I use the parser like this:
boost::spirit::qi::uint_parser
hex_byte; std::string str("..."); std::vector
vec; iter_type curr=str.begin(), end=str.end();
bool r=phrase_parse(curr, end, +hex_byte, space, vec);
Is vec going to be copied somewhere inside of qi? Or are the bytes directly appended to the vec? I would like to reserver some space for the maximum possible input and avoid additional internal copies inside of qi...
How does the behaviour changes std::vector
is part of the fusion::map like fusion::map < fusion::pair
, fusion::pair ... , fusion::pair > data_item;
Are the fields of the map used directly while parsing, or are there some temporaries, which will be first created (somewhere inside qi core) and filled with data and afterwards assigned to the corresponding map field?
The general idea is for all attributes to be directly used to receive the parsed data. Period. As you might imagine this is not always true. You have to be aware of a couple of pitfalls in order to avoid additional copies inside the parser generated from a Spirit.Qi expression. 1) Don't use semantic actions, these need to instantiate an instance of the attribute in order to pass it to the function (object) to be called. 2) Alternatives currently are known to create a new instance of the attribute as well. This is a known issue and we need to come up with a better solution. 3) Somebody posted examples on the Spirit ML a while ago, demonstrating that certain constructs cause additional copying, but I'm not able to find that, currently. All I remember is that it seemed to be possible to overcome those problems as well. We just have not have the time to look into this more closely yet. HTH Regards Hartmut --------------- http://boost-spirit.com
Hartmut,
thanks for the answer. I don't use semantic actions and my alternatives are
only used in the case where I omit some tokens, so there should not be any
copies than.
Really great lib! I enjoy using it.
Ovanes.
On Thu, Oct 7, 2010 at 3:29 PM, Hartmut Kaiser
...
The general idea is for all attributes to be directly used to receive the parsed data.
Period.
As you might imagine this is not always true. You have to be aware of a couple of pitfalls in order to avoid additional copies inside the parser generated from a Spirit.Qi expression.
1) Don't use semantic actions, these need to instantiate an instance of the attribute in order to pass it to the function (object) to be called. 2) Alternatives currently are known to create a new instance of the attribute as well. This is a known issue and we need to come up with a better solution. 3) Somebody posted examples on the Spirit ML a while ago, demonstrating that certain constructs cause additional copying, but I'm not able to find that, currently. All I remember is that it seemed to be possible to overcome those problems as well. We just have not have the time to look into this more closely yet.
HTH Regards Hartmut --------------- http://boost-spirit.com
participants (2)
-
Hartmut Kaiser
-
Ovanes Markarian