wangxiaowei0303 / rapidjson

Automatically exported from code.google.com/p/rapidjson
MIT License
0 stars 0 forks source link

Complex Values are not movable out of Document #60

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
When using complex values such as arrays or objects, you cannot detach these 
from Document if the Document gets freed. Attached is a simple example program 
of this behaviour and valgrind logs showing that the values are indeed freed. 

RapidJson version 0.11
Ubuntu 12.04 64 bit
g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
GNU C Library (Ubuntu EGLIBC 2.15-0ubuntu10.3) stable release version 2.15

Original issue reported on code.google.com by cmous...@gmail.com on 4 Feb 2013 at 5:20

Attachments:

GoogleCodeExporter commented 9 years ago
It is because the values are allocated by document's allocator in the code. You 
can use a allocator (e.g. a document) that stays alive with the value. Or just 
use a document instead of value in the function parameter.

Original comment by milo...@gmail.com on 5 Feb 2013 at 4:52

GoogleCodeExporter commented 9 years ago
Yes. This is evident from what happens. But it unfortunately does prevent one 
from detaching a value from document to simplify code? How would you fix this 
code to work properly?

Original comment by cmous...@gmail.com on 5 Feb 2013 at 7:30

GoogleCodeExporter commented 9 years ago
You may clone the value to a document, which can be done by using Accept(). 

Otherwise, as I mentioned, you can use another allocator when creating the 
values. Using CrtAllocator will not destroy the memory buffer as the default 
MemoryPoolAllocator.

Original comment by milo...@gmail.com on 5 Feb 2013 at 10:59