Small size.
The kernel uses this (written by Linus) which takes only six bytes.
Code: Select all
loop:
lodsb
stosb
test al,al
jnz loop
Small size.
Code: Select all
loop:
lodsb
stosb
test al,al
jnz loop
I do this out of interest and curiosity. Also, I find pointer-based solutions to data-structure algorithms fascinating ("move pointers, not the data"), although I know that it is harder to write, debug, maintain and understand. Better reserve those complex and efficient routines for runtimes of higher languages like Python, Ruby, Clojure and JavaScript.
My grandpa used to say: "He who thinks in pennies will never be a millionaire", but I think this was more in response to "penny wise pound foolish". He didn't get very rich, btw.There is a saying "Look after the pennies, and the pounds look after themselves".
Thanks. Lots of developers create software bloat by putting layers and layers over old layers (like an onion) and never trim the fat. I suspect that is the case for Microsoft Windows, amongst others. Webbrowsers are indeed another good example, they tend to get more bloated the older they get.You will be unlikely to write the sort of bloated slow code that's too common nowadays.
I remember REP STOSB, but then of course you must know in advance how many bytes you want to copy.
Well, that just you.Heater wrote: ↑Tue Jul 23, 2019 6:38 amejolson,Hmm... let me have a go at that. Something like:To document in a high-level language what strcpy semantically means?No seriously. Whichever way I read the C language standard the only way I can interpret strcpy() is as "undefined behavior".Code: Select all
char *strcpy(char *dest, const char *src) { for (int i = 0 ; i < rand() ; i++ ) { *dest++ = (char)rand(); } return dest; }
It's not even possible to write a function in a high level language that does what C's strcpy does. Well, except C++ of course![]()