Fastest way to zero a slice of memory

Nordlöw per.nordlow at gmail.com
Sun Mar 4 15:23:41 UTC 2018


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?


More information about the Digitalmars-d-learn mailing list