Writing a large file would be much more efficient if the writer operated on a stream rather than on a string.
Currently, the entire file must exist in-memory as a string before it can be written to disk. And since strings are memcpy'd as they are lengthened, an extra copy of the file exists in-memory while it is being generated. So writing a 1GB JSON file requires 2GB of memory in addition to the memory required to store the jsoncpp datastructures (which can be another 1GB or so).
If instead the writer operated on streams, the user could supply a stringstream to get a string when desired.
At my company, we have to switch away from jsoncpp to alternative storage methods when the filesize exceeds several hundred MB because of the huge memory requirements.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Writing a large file would be much more efficient if the writer operated on a stream rather than on a string.
Currently, the entire file must exist in-memory as a string before it can be written to disk. And since strings are memcpy'd as they are lengthened, an extra copy of the file exists in-memory while it is being generated. So writing a 1GB JSON file requires 2GB of memory in addition to the memory required to store the jsoncpp datastructures (which can be another 1GB or so).
If instead the writer operated on streams, the user could supply a stringstream to get a string when desired.
At my company, we have to switch away from jsoncpp to alternative storage methods when the filesize exceeds several hundred MB because of the huge memory requirements.
I am adding StyledStreamWriter.