godot
godot copied to clipboard
[Memory] Add `calloc_static` method
Adds new method calloc_static to class Memory
The logic of
ptr = (int *)Memory::calloc_static(size, sizeof(int));
is the same as
ptr = (int *)Memory::alloc_static(size * sizeof(int));
memset(ptr_zero, 0, size * sizeof(int));
But then why this is necessary?
The point is that calloc is much more optimized for this.
Read more here https://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc
I'd suggest presenting and using actual use cases when adding a core method like this, and discussing the need for it with the team, as it's very core
Nice catch!
When searching with the following regex alloc.*\n.*memset I found a few more places where this can be used:
in audio_stream_wav.cpp and shader_gles3.cpp