0

I'm making the assumption that the array of strings passed into the main function as argv in void main( int argc, char* argv[] ) remains in scope for the duration of the application.

My question is therefore whether it is possible, using boost::program_options to get a pointer to the actual element in argv which represents a particular option.

That is, rather than allocating a std::string when parsing, it is possible to just get a pointer to the start of a string option value.

Nick
  • 25,026
  • 7
  • 51
  • 83
  • What for? The overhead of allocating a std::string will likely be negligible. – James M Mar 08 '12 at 10:07
  • @JamesMcLaughlin this is a special use case where command line parameters must be parsed repeatedly in a tight loop. – J.N. Mar 08 '12 at 10:08
  • The problem I'm trying to solve is that whilst the allocation of a string is negligible it appears as a memory leak as it's getting assigned to a static variable. – Nick Mar 08 '12 at 10:11
  • PS. And yes I could checkpoint the memory after the assignment but for various reasons I don't want to. – Nick Mar 08 '12 at 10:12
  • 1
    I'm just throwing an idea out there, as I haven't checked the source. But usually most building blocks in boost which are string dependent are actually typedefs which instantiates templates that are paramatized on string type. This is because generally they want to provide both narrow & wide type options. If this is the case you can probably just throw your own string class in there which could probably do exactly what you want, as long as you provide a std::[w]string like interface. – Ylisar Mar 08 '12 at 10:20

0 Answers0