Cleaning a bit of memory by "const" or "#define"
For example, If I used much plugin who use a lot of 'datas' (offset, custom values, etc), what is the best method to hold these 'datas' whit "const" or "#define" ?
If I use "#define" while clear a bit of memory, for example: PHP Code:
PHP Code:
What is the better solution ? Thanks, and sorry for stupid question. |
Re: Cleaning a bit of memory by "const" or "#define"
I think the difference is trivial as long as you tak about numbers.
|
Re: Cleaning a bit of memory by "const" or "#define"
In such case, meaning defining a simple value, both #define and const are equivalent.
In others words, both values will be replaced at compilation time. The advantages using const is to have a better error checking and the ability to create tagged constants. I would use always const to define simple values. |
Re: Cleaning a bit of memory by "const" or "#define"
Quote:
|
Re: Cleaning a bit of memory by "const" or "#define"
Quote:
|
Re: Cleaning a bit of memory by "const" or "#define"
Not sure why it needs examples...
Random and stupid ones : #define SIZE 2.5 new array[ SIZE ]; // Compiler happy const SIZE = 2.5 new array[ SIZE ]; // Tag mismatch #define RANDOM "LoL" // or random value like 66.6. #define MACRO(%0) ( %0 * RANDOM ) // Compiler happy const RANDOM = "LoL" // error const RANDOM = 66.6 #define MACRO(%0) ( %0 * RANDOM ) // tag mismatch |
Re: Cleaning a bit of memory by "const" or "#define"
Quote:
Thanks for clarification. |
Re: Cleaning a bit of memory by "const" or "#define"
Quote:
|
Re: Cleaning a bit of memory by "const" or "#define"
Yes, special case for Pawn. I've checked with amxxdump.
|
Re: Cleaning a bit of memory by "const" or "#define"
I can't remember where I read, If You know what type of datas you set on functions is better for memory to declare/use these datas with "#define". Not sure if that's true or doesn't matter.
|
| All times are GMT -4. The time now is 06:12. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.