[Asterisk-Dev] FW: asterisk/doc CODING-GUIDELINES,1.4,1.5
Michael Giagnocavo
mgg-digium at atrevido.net
Tue Jan 18 17:06:04 MST 2005
>+If you are going to reuse a computable value, save it in a variable
>+instead of recomputing it over and over.
>+
>+Just an Example:
>+
>+ if (strlen(name)) {
>+ newname = alloca(strlen(name));
>+ strncpy(newname, name, strlen(name);
>+ }
>+
>+vs
>+
>+ if((len = strlen(name))) {
>+ newname = alloca(len);
>+ strncpy(newname, name, len);
>+ }
Maybe they should point out that you need to make the memory versus CPU
cycles after you calculate the hit... i.e., using a nice amount of memory to
store a value that's easily computed is MUCH worse than wasting a few
hundred cycles, since one cache miss is gonna knock you back a lot...
-Michael
More information about the asterisk-dev
mailing list