Raised This Month: $ Target: $400
 0% 

Is this execution correct?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-22-2022 , 00:29   Re: Is this execution correct?
Reply With Quote #3

Quote:
Originally Posted by damage220 View Post
1. You should never use sizeof( in a loop condition. Create a variable and store the size in it.
That's the first time I've ever heard this in the 15 years I've been around here. I was under the impression that sizeof was evaluated at compile-time (except in specific use cases). I've only ever heard people say that you shouldn't use a function (sizeof is not a function, it's an operator) in a for or while loop's definition if the value will not change during the loop.

Quote:
Originally Posted by damage220 View Post
2. To speed up execution, move static arrays out to global scope, precache them.
This is not good advice. If something is only used in that function and has no usefulness to other areas of code, it should not be global (making a local variable/constant global just pollutes the global namespace).

If it's relatively small and the function is not called very often then it's generally negligible to declare it as "new". If it never changes then it should be declared as a constant ("const"). If it's a large variable (e.g. an array with a lot of cells) and it's not constant, it should be declared as a static variable ("static").
__________________
fysiks is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:38.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode