what is the memory overhead for boost::property_tree::ptree
Asked Answered
S

1

7

I have found that boost::property_tree::ptree has an enormous memory overhead. My estimate is that an empty ptree is about 150 bytes, and, any entry put in a ptree adds at least another 150 bytes. This makes it unusable for us for trees containing thousands of entries.

Is my estimation off? Is there some way to keep the overhead low?

Slacker answered 25/5, 2013 at 2:18 Comment(0)
C
2

Boost.PropertyTree is basically not a fast or lightweight parser.
It focuses on providing high layer convenience and functionalities, so it is not built to be efficient, I guess.

You could see this thread on boost mailing list for a similar question.

I'd suggest that an alternative of Boost.PropertyTree might be either:

  • a SAX parser -- this is an another approach for XML parsing. It's like an opposite of DOM parser; it parses XML nodes one by one. Usually, the "memory allocation for entire file at the begginning" occurs in a DOM parser, but it won't occur on SAX parsers.
  • an allocator-customizable parser + user defined memory pool -- you could configure the allocator of such parser to point the stable memory pool. It could simply be a large buffer of pre-allocated memory, a fragmentation-aware pool, or even a memory-mapped file, etc...
Chime answered 8/6, 2013 at 16:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.