two sets up code, which both do the same thing:
CustomType* ct;
ct = (CustomType*) malloc(sizeof(CustomType));
memset(ct, 0, sizeof(CustomType));
or
CustomType* ct;
int sizeOfCustomType = sizeof(CustomType);
ct = (RingQueueType*) malloc(sizeOfCustomType);
memset(ct, 0, sizeOfCustomType);
Which is more efficient in term of speed and size.
My thought is that they both compile out to the same thing, while the
second option gives you better insight into debugging (i.e. look at the
sizeof value [our embedded debugger can't evaluate methods
(sizeof(CustomType)) ]).
The argument against is that the second option uses an extra int value,
therefore increasing stack size. Some believe, which may be true
depending on optimization settings, that the first is less efficient
from a speed standpoint because it calls sizeof() an extra time.
Any thoughts? Replace the sizeof() call with any frequently used call
in a given method. I.E. is it better to set a variable based on a
single call and then re-use the variable, or make multiple calls to the
same method, with the same paramters.
doSomething(customCall(constantVal););
doSomethingElse(customCall(constantVal););
doYetAThirdThing(customCall(constantVal););
or
int customCallVal = customCall(constantVal);
doSomething(customCallVal);
doSomethingElse(customCallVal);
doYetAThirdThing(customCallVal);
Thanks
To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>.
| Yahoo! Groups Sponsor | |
|
|
Yahoo! Groups Links
- To visit your group on the web, go to:
http://groups.yahoo.com/group/c-prog/
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
