-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
str() gives incorrect result after scoped object has been destructed #15
Comments
I can see what's going on here though I'm not sure if we actually want to change the behaviour to maintain performance. Just to set things out before explaining: If you create a rabbit value/object/array and it is the root value/object/array we come up with a new allocator for it and keep it alongside the underlying rapidjson value, this way all allocating steps that you take on the value afterwards just work and you don't have to think about allocators. When the root value gets destructed we destroy the allocator and all memory that was allocated with it. So breaking down the 3 cases you describe: Case 1: you have 3 separate allocators for the 3 different "root" values, you may not be intending for them to be root values but because they were not created via methods on another rabbit value of some kind (eg operator[]) they are "root" values. When you add all of them up into Case 2: You have essentially the same thing happening as Case 1 you just happen to luck out with regards to the lifetime of the rabbit objects sticking around and so the allocators haven't been destructed yet. Case 3: You are telling Case 3 is the ideal usage for performance reasons (which if you are interested in rapidjson and by extensioni rabbit, you are probably interested in performance) as far as I'm aware. The only alternative I can see that we could implement into rabbit would be to check if when calling insert/push_back/etc... we have two different allocators and if thats the case do a deep copy, which I'm not sure we would want to do. If we did that automatically for you it may not be obvious where there is a possibly large performance hit. For example if we did that for Case 1, your program would work as you seem to expect it to, but, you would have the following: |
Thank you for detailed explanation! I got the idea. Probably case 3 is the best deal from performance perspective, though I wouldn't mind for a deep copy in some cases. To me it's rather to have an option - performance vs convenience. I think it's worth to mention in readme or even cover in the tests this scenario. Thank you! |
Consider following example:
Expected behavior: str() is working after obj1 destruction.
This code works as expected:
Also you can pass allocator for temp objects:
The text was updated successfully, but these errors were encountered: