Fastest way to zero a slice of memory

bauss jj_1337 at live.dk
Sun Mar 4 15:28:39 UTC 2018


On Sunday, 4 March 2018 at 15:23:41 UTC, Nordlöw wrote:
> When zeroing a slice of memory (either stack or heap) such as
>
>     enum n = 100;
>     ubyte[n] chunk;
>
> should I use `memset` such as
>
>     memset(chunk.ptr, 0, n/2); // zero first half
>
> or an array assignment such as
>
>     chunk[0 .. n/2] = 0; // zero first half
>
> or are they equivalent in release mode?
>
> Further, does it depend on whether the slice length is known at 
> compile-time or not?

This is worth reading:

https://stackoverflow.com/questions/3654905/faster-way-to-zero-memory-than-with-memset


More information about the Digitalmars-d-learn mailing list