-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Reserve and resize function for basic json #1935
Comments
In order to asses your issue, we need the following information:
|
I just came to ask the same question... I have a json array that I'm going to insert some known (or approximate) number of elements into, and I'm observing in the profile that the vector resize operation is showing up as a significant portion of the time. Normally I would call vector::reserve() in order to avoid this re-allocation and copying (and possibly use resize() after finishing the inserts when the final size is known although this is usually much less important), however, these don't seem to be exposed on the json array. Ah, I figured it out:
|
@abrownsword This is exactly what I was asking; std::vector has a reserve(n) function, this json library does not |
@boredbored We can do more things when we get the ref or pointer. If we add reserve and resize, the other functions of std::vector should be added too. |
I do not think adding this functions would be too intuitive, as it could not do anything if the stored JSON value was a number/bool/null/object, etc. |
It also relies on knowing that the underlying container has a reserve method. I gave the syntax above by which the goal can be accomplished. That ought to be sufficient? |
I agree that doing it via pointer or reference is the best way. |
I think it is enough.
Just as i said, there will be endless works if we add reserve and resize. This issue can be closed, i think. The example is figured out. |
I’ve tried to find out how to call the std::vector::reserve in the basic json via get_ref but I can’t figure out how.
Can you please implement a reserve and resize function for the json?
The text was updated successfully, but these errors were encountered: