According to link, memset accepts an int for the value to be set. Why an int, if memset set each byte in the buffer?
I can only imagine that memcpy tries to optimize by copying 4 bytes at a time.
Thanks.
According to link, memset accepts an int for the value to be set. Why an int, if memset set each byte in the buffer?
I can only imagine that memcpy tries to optimize by copying 4 bytes at a time.
Thanks.
The reason for taking an int is probably hysterical^Whistorical - someone wrote it that way a long time ago, and it's still that way.
It really doesn't make much difference, the value is either passed on the stack as a 4-byte aligned value (in a 32-bit processor), or it is passed in a register. Either way, a unsigned char or some such would take up the same resource (memory or register).
Any decision to optimize it by writing multiple bytes at a time is purely internal to memset, and completely irrelevant to what parameters it takes.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
I am asking this because I never paid attention to this paramter. But recently I saw that a developer in my team changed memset call in a legacy code that I am working from:
To:Code:memset(buff, 0xFF, size)
Which seems pointless...Code:memset(buff, 0xFFFFFFFF, size)
That will have no effect on the actual content in buff at all - both will do the same thing.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.