c++windowsvisual-studio-2008

Is filling memory with non zero values slower than filling it with zeros?


I'm not very expert on how processors work, but one might imagine that it was easier to set chunks of memory to zero than non zero values and so it may be marginally faster.


Solution

  • I think the only difference would be in setting up the register that has the value to store to memory. Some processors have a register that's fixed at zero (ia64 for example). Even so, whatever minuscule overhead there might be for setting up a register will be monstrously dwarfed by the writing to memory.

    As far as the time to actually write to the memory - that'll be clocked the same on all architectures I'm familiar with.