What is the equivalent of memset in C#?

You could use Enumerable.Repeat: byte[] a = Enumerable.Repeat((byte)10, 100).ToArray(); The first parameter is the element you want repeated, and the second parameter is the number of times to repeat it. This is OK for small arrays but you should use the looping method if you are dealing with very large arrays and performance is a … Read more

Reset C int array to zero : the fastest way?

memset (from <string.h>) is probably the fastest standard way, since it’s usually a routine written directly in assembly and optimized by hand. memset(myarray, 0, sizeof(myarray)); // for automatically-allocated arrays memset(myarray, 0, N*sizeof(*myarray)); // for heap-allocated arrays, where N is the number of elements By the way, in C++ the idiomatic way would be to use … Read more

Why use bzero over memset?

I don’t see any reason to prefer bzero over memset. memset is a standard C function while bzero has never been a C standard function. The rationale is probably because you can achieve exactly the same functionality using memset function. Now regarding efficiency, compilers like gcc use builtin implementations for memset which switch to a … Read more