Open MAGNAT2645 opened 4 years ago
With experiments, found out that static char
doesn't work with FormatEx
. I may end up not using static
whenever I need formatting.
This might be because static
vars store their values into memory and keep them even after function end.
Description
You can add some optimizations to all of FF2 code, i think. These changes aren't so large but they can improve your code execution (i mean, execution speed). It's just a little advice, you don't have to use it if you don't want to.
Applications
You can optimize string checks, string formats and reduce var usage (by freeing the variable from memory earlier than at the end of the function).
Code Snippet
1) You can replace Format functions with FormatEx wherever the output buffer is not used as the same input buffer. Like:
This method can make your code faster a bit.
2) You can replace some string codes. if ( strlen( string ) ) can be replaced with if ( string[0] != 0 ) (or even if ( string[0] != '\0' ) if you use it to check that string isn't empty. strcopy( buffer, sizeof( buffer ), "" ); and Format( buffer, sizeof( buffer ), "" ); can be replaced with buffer[0] = 0 (or even buffer[0] = '\0') if you want to empty string. These methods can make your code faster a bit too.
3) Last thing is that you can use code blocks without any condition (just to restrict local vars). Vars that exist inside block will be freed at the block end. So you can put some vars into separate blocks and these vars will exist only while block is executing. (they won't exist until the end of the whole function)
can be replaced with:
Other Information
There are some advanced mini-lessons about how SourcePawn works and described some hidden features. But ONLY in Russian! (you can use google translation or i can try to explain you something from those lessons) Here.