c - Runtime of Initializing an Array Zero-Filled -


if define following array using zero-fill initialization syntax on stack:

int arr[ 10 ] = { 0 }; 

... run time constant or linear?

my assumption it's linear run time -- assumption targeting fact calloc must go on every byte zero-fill it.

if provide why , not it's order xxx tremendous!

the runtime linear in array size.

to see why, here's sample implementation of memset, initializes array arbitrary value. @ assembly-language level, no different goes on in code.

void *memset(void *dst, int val, size_t count) {     unsigned char *start = dst;     (size_t = 0; < count; i++)         *start++ = value;     return dst; } 

of course, compilers use intrinsics set multiple array elements @ time. depending on size of array , things alignment , padding, might make runtime on array length more staircase, step size based on vector length. on small differences in array size, make runtime constant, general pattern still linear.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -