miloyip/rapidjson — pull request #105 by miloyip (2014-08-17 12:44:55+00:00)
Title: Memory optimization

As `Stack` are expanded when it is full, using `MemoryPoolAllocator` previously does not have advantage. It makes `Document` mixes up with unused (but not freed) smaller stack buffers and `Value`s. They should be allocated by `CrtAllocator` by default.

`Reader` and `Writer` can change this default allocator easily. But `Document` mixes two types of things to be allocated. So, this pull request separate it into two allocators. One is for allocating values, another is for allocating stack.

Besides, `Stack` is refactor to support `ShrinkToFit()` feature. It also allocates the stack buffer lazily. These two changes make `Document` not need to allocate stack buffer if it is not used for parsing (User can create a `Document` programatically). Also after parsing, use `ShrinkToFit()` after `Clear()` to completely free the stack buffer.

`StringBuffer` and `MemoryBuffer` also supports `StrinkToFit()` when user want to reduce the memory after stringify.