Raised This Month: $29 Target: $400
 7% 

Constants in multiple plugins


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 05-16-2017 , 00:22   Constants in multiple plugins
Reply With Quote #1

If I have an include file such as:

PHP Code:
#if defined _pdata_offsets_inc
  #endinput
#endif
#define _pdata_offsets_inc

const m_pPlayer 41;
const 
m_flNextPrimaryAttack 46;
const 
m_flNextSecondaryAttack 47;
const 
m_fInReload 54;
... 
When I call #include <pdata_offsets_inc> from multiple plugins, will it allocate memory just once for these values or each time the include is called from each plugin?
vitorrossi is offline
[email protected]
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-16-2017 , 02:06   Re: Constants in multiple plugins
Reply With Quote #2

Constants like these work as macros.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 05-16-2017 , 10:36   Re: Constants in multiple plugins
Reply With Quote #3

Quote:
Originally Posted by [email protected] View Post
Constants like these work as macros.
My understanding is that a macro such as:

PHP Code:
#define var 5

new szArray[16];

szArray[var] = 7;
szArray[2] = var; 
Uses twice as much memory as the following since #define is done in the preprocessor allocating the value 5 each time it is used within the code, while the const holds one place in memory where that value is stored

PHP Code:
const var 5

new szArray[16];

szArray[var] = 7;
szArray[2] = var; 
Is this wrong?

Last edited by vitorrossi; 05-16-2017 at 10:40.
vitorrossi is offline
[email protected]
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 05-16-2017 , 11:07   Re: Constants in multiple plugins
Reply With Quote #4

Quote:
Originally Posted by vitorrossi View Post
as the following since #define is done in the preprocessor allocating the value 5 each time it is used within the code
It doesn't allocate it, it is directly inserted in code section.
Quote:
Originally Posted by vitorrossi View Post
while the const holds one place in memory where that value is stored
Quote:
Originally Posted by vitorrossi View Post
PHP Code:
const var 5

new szArray[16];

szArray[var] = 7;
szArray[2] = var; 
Code:
const var = 5
const works here the same as macro.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-16-2017 , 19:19   Re: Constants in multiple plugins
Reply With Quote #5

The memory requirements are going to be negligible regardless of how you do it. It's not worth trying to do micro-optimizations.
__________________

Last edited by fysiks; 05-16-2017 at 19:20.
fysiks is offline
Reply


Thread Tools
Display Modes

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 17:20.


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