You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the problem or limitation you are having in your project
Currently Dictionary has no way to reserve a know amount of memory, but HashMap does with the reserve() function.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Currently when inserting a large number of elements into an Array the ideal way to do it would be to first resize and then add elements instead of just using push_back. Dictionary should be able to do the same thing. Adding the reserve method to Dictionary would make it so you can avoid a ton unnecessary memory allocations and rehashes in languages outside of C++, where you can’t just use HashMap directly. Not reserving memory for the HashMap is probably worse than not doing it for Array too since it mallocs a new block of memory and copies the old data in on every resize instead of reallocing like Array does.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Should be simple to add just bind the method in Dictionary and have it call the reserve method from it’s DictionaryPrivate then write some documentation and maybe add a test. I could write the code to do it if approved.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No.
Is there a reason why this should be core and not an add-on in the asset library?
Not possible.
The text was updated successfully, but these errors were encountered:
GDScript has a lot of overhead, so not all functions that are important in C++ are important in GDScript. Before exposing reserve, we should measure whether it makes an important enough difference to warrant the additional complexity for GDScript users.
(Although, I suppose, it may still be worth it for C++ and Rust users, where it will definitely make a large difference)
Describe the project you are working on
Prototyping a game.
Describe the problem or limitation you are having in your project
Currently Dictionary has no way to reserve a know amount of memory, but HashMap does with the reserve() function.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Currently when inserting a large number of elements into an Array the ideal way to do it would be to first resize and then add elements instead of just using push_back. Dictionary should be able to do the same thing. Adding the reserve method to Dictionary would make it so you can avoid a ton unnecessary memory allocations and rehashes in languages outside of C++, where you can’t just use HashMap directly. Not reserving memory for the HashMap is probably worse than not doing it for Array too since it mallocs a new block of memory and copies the old data in on every resize instead of reallocing like Array does.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Should be simple to add just bind the method in Dictionary and have it call the reserve method from it’s DictionaryPrivate then write some documentation and maybe add a test. I could write the code to do it if approved.
If this enhancement will not be used often, can it be worked around with a few lines of script?
No.
Is there a reason why this should be core and not an add-on in the asset library?
Not possible.
The text was updated successfully, but these errors were encountered: