Raised This Month: $51 Target: $400
 12% 

Question about memory


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 03-12-2015 , 11:50   Question about memory
Reply With Quote #1

What's the best? (and why)
Code:
enum _:Types
{
    Connected,
    Alive,
    Retarded
}

new bool:g_Bools[MAX_PLAYERS + 1][Types]

public client_putinserver(id)
    g_Bools[id][Connected] = true
or:
Code:
new bool:g_bConnected[MAXPLAYERS + 1], bool:g_bAlive[MAXPLAYERS + 1], bool:g_bRetarded[MAXPLAYERS + 1]

public client_putinserver(id)
    g_bConnected[id] = true
__________________
Jhob94 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-12-2015 , 12:42   Re: Question about memory
Reply With Quote #2

The first method is more organized and potentially could be faster but I'm not 100% on that.

My thought: In the first one, everything is stored in one array so when accessing data you only need to seek the address of the variable then offset it by ( id * size ) + item. Using separate variables, each variable is stored at a different memory address. In most cases this doesn't matter, but there are scenarios where it's applicable. Would you ever notice a difference, no.
__________________

Last edited by Bugsy; 03-12-2015 at 12:44.
Bugsy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-12-2015 , 12:44   Re: Question about memory
Reply With Quote #3

I prefer the first one, but this is a subjective opinion. I think that the difference, if it exists, is trivial because you initialize the same number of variables(even if in one array same ammount memory is allocated - someone correct me if I'm wrong).
__________________

Last edited by HamletEagle; 03-12-2015 at 12:45.
HamletEagle is offline
Reply



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 05:13.


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