3 ms·
To illustrate the advantage of memcpy, consider this inner loop possible implementation: mov EAX,[ESI] mov EBX,4[ESI] mov ECX,8[ESI] mov EDX,12
by WalterBright 8y ago
To illustrate the advantage of memcpy, consider this inner loop possible implementation:
mov EAX,[ESI]
mov EBX,4[ESI]
mov ECX,8[ESI]
mov EDX,12[ESI]
mov [EDI],EAX
mov 4[EDI],EBX
mov 8[EDI],ECX
mov 12[EDI],EDX
add ESI,16
add EDI,16
Modern processors can likely do the 4 loads and 4 stores in parallel. That can't be done with 0 terminated strings, as you have to check every byte for 0. Even worse, you have to take care not to seg fault by reading too far past the 0, as there may not be any valid memory there.
- gpderetta 8y agoWell, you can use vevctorized string operations that allow for null terminated strings. I do agree with the general idea that null terminated strings are a mistake though.