Raised This Month: $ Target: $400
 0% 

Arrays (Better coding methods) Expirenced programmers only


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 04-04-2006 , 17:57   Arrays (Better coding methods) Expirenced programmers only
Reply With Quote #1

[OFF TOPIC]Like title says I don't want people who don't know what their talking about giving dumb answers.[/OFF TOPIC]

[ON TOPIC]

Ok so what I want to know is which method is better for reading and speed.

Say you want to store two or more values per user that have to do with the same thing. What would be a better way of storing it. (Explained in detail below)
1) 2D array with player ID first then split into two or three
2) 2D array split in two or three then into player IDs
3) 2 or more different arrays of just player IDs

Method #1: 2D array Player first (Code then diagram attached)
Code:
// [PLAYER][0] = how many kills // [PALYER][1] = how many deaths new g_PlayerStuff[33][2] //.... console_print(id , "You have %d kills and %d deaths" , g_PlayerStuff[id][0] , g_PlayerStuff[id][1]) //... Or would this be better new kills = g_PlayerStuff[id][0] new deaths = g_PlayerStuff[id][1] console_print(id , "You have %d kills and %d deaths" , kills , deaths)

Method #2: 2D array split first (Code then diagram attached)
Code:
// [0][PLAYER] = how many kills // [1][PLAYER] = how many deaths new g_PlayerStuff[2][33] //.... console_print(id , "You have %d kills and %d deaths" , g_PlayerStuff[0][id] , g_PlayerStuff[1][id]) //... Or would this be better new kills = g_PlayerStuff[0][id] new deaths = g_PlayerStuff[1][id] console_print(id , "You have %d kills and %d deaths" , kills , deaths)
Method #3: 2 arrays (Code then diagram attached)
Code:
new g_PlayerKills[33] new g_PlayerDeaths[33] //... console_print(id , "You have %d kills and %d deaths" , g_PlayerKills[id] , g_PlayerDeaths[id])

Keep in mind that I'm not talking about just saving kills and deaths that was just the first things that came to mind when typing this for an example.
Attached Images
File Type: jpg method-3.jpg (9.4 KB, 181 views)
File Type: jpg method-2.jpg (12.2 KB, 187 views)
File Type: jpg method-1.jpg (9.4 KB, 168 views)
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
 


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 16:37.


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