register_plugin, defines and constants.
I wanted to know that why do most of the coders use defines for registering plugin.
Plugin can be registered using PHP Code:
PHP Code:
PHP Code:
1, 2 or 3? In wiki, they have said that constants are better than defines. |
Re: register_plugin, defines and constants.
1 & 2 are identical to the compiler.
2 is used for readability. 3 is used when you use the value more than once, typically used with Version |
Re: register_plugin, defines and constants.
Sir. What do you mean by more than once? Which one do you prefer?
|
Re: register_plugin, defines and constants.
i prefer the 1 .
|
Re: register_plugin, defines and constants.
PHP Code:
Search page with pre-processor here : http://www.compuphase.com/pawn/Pawn_Language_Guide.pdf PHP Code:
|
Re: register_plugin, defines and constants.
Thanks DWIGHTpN. But I'm not going to read that long guide! hehe.
|
Re: register_plugin, defines and constants.
Defines are replaced on compile time, so the string gets copied wherever you use it. Constants are initialized on plugin startup and the string is stored in memory with a pointer, which will be a better performer if you use it more than once as it won't have to be reinitialized.
|
Re: register_plugin, defines and constants.
Quote:
|
Re: register_plugin, defines and constants.
I don't think making a variable "const" will have an effect on memory reservation. If you're talking about global variables, then no. If you only use it once it's better to use the defines or just the plain strings since they are released from the memory when the public function ends.
Although I'm no expert, so I might be wrong here. |
Re: register_plugin, defines and constants.
Defines are replaced by the compiler's preprocessor before compilation. So example 1 and 2 are *exactly* the same in the end. Using defines you can get that info to the top of the file for convenience, and update multiple occurances of the same string with ease.
Using a global const variable is helpful because the AMXX compiler is not clever enough to collapse usages of the same string literal into one. So if you write "1.0.0" as your version string ten times in your plugin (or use an equivalent define) it will actually end up ten times in the file. |
| All times are GMT -4. The time now is 09:44. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.