godot icon indicating copy to clipboard operation
godot copied to clipboard

[Memory] Add `calloc_static` method

Open Nazarwadim opened this issue 1 year ago • 1 comments

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

Nazarwadim avatar May 06 '24 19:05 Nazarwadim

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

AThousandShips avatar May 06 '24 19:05 AThousandShips

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

Geometror avatar May 07 '24 23:05 Geometror