August 19, 2004
Three questions for Walter:

1) why does memset() do the following instead of using a "stosd"
instruction?

xor eax, eax
loop:
mov [dst], eax
mov [dst+4], eax
mov [dst+8], eax
mov [dst+12], eax
mov [dst+16], eax
...
add dst, 32
dec ecx
jne loop

Is the latter faster than a stosd?


2) when duplicating array content (array.dup), the code allocates an
equivalently sized chunk from the heap, clears it all to zero (using memset,
as above), and then does a memmove() to copy the source-data.  Surely the
memset() is entirely redundant?


3) when creating a new array, it is cleared to the default value for the
type (e.g. 0xff for char[]). If you subsequently extend the array size via
"array.length = ", the content is memset() to zero: /not/ to the default
value. Why is that?


August 20, 2004
"van eeshan" <vanee@hotmail.net> wrote in message news:cg14ch$2gnq$1@digitaldaemon.com...
> Three questions for Walter:
>
> 1) why does memset() do the following instead of using a "stosd"
> instruction?
>
> xor eax, eax
> loop:
> mov [dst], eax
> mov [dst+4], eax
> mov [dst+8], eax
> mov [dst+12], eax
> mov [dst+16], eax
> ...
> add dst, 32
> dec ecx
> jne loop
>
> Is the latter faster than a stosd?

Yes.


> 2) when duplicating array content (array.dup), the code allocates an
> equivalently sized chunk from the heap, clears it all to zero (using
memset,
> as above), and then does a memmove() to copy the source-data.  Surely the
> memset() is entirely redundant?

Probably.

> 3) when creating a new array, it is cleared to the default value for the
> type (e.g. 0xff for char[]). If you subsequently extend the array size via
> "array.length = ", the content is memset() to zero: /not/ to the default
> value. Why is that?

Bug.