How memory intensive are arrays? safe to use say 300?
by Flybynight Studios · in Torque Game Engine · 07/19/2008 (9:39 am) · 2 replies
I'm just putting some finishing touches on a new inventory system. It's highly customized for my application and it's very detailed. In order to get the most out of my item details I thought it best to set an array for each item. That gives me a pretty much endless area of expandability as far as details goes per item but at what cost I am wondering..
My thoughts are variables vs arrays.. I could simply make 30 variables per item using $item1_1, $item1_2... $item13_3, $item13_4 etc etc.. but a far more efficient way of playing with the data and managing it would obviously be arrays.
In my particular situation I will be using 5-7 container items (an array on their own containing Item IDs) and an array for each item itself. So basically if I have a 50 slot container, the container1 array has 51 indexes with indexes 1-50 containing itemIDs that are associated with their own array $itemxx.array that might have 30-40 indexes as well.
- When I remove an item from the inventory I reset that item.array to a single index
- When I destroy a container (IE move it) I wipe out the container array
Is this acceptable use of arrays or am I going to run into memory leak issues on the client? Anyone got any thoughts on this? Obviously flatfile text files are an option but they are slow and much more intensive to parse than a simple array call.
Am I going to get spanked you think running say 300-400 arrays?
Thanks in advance.
My thoughts are variables vs arrays.. I could simply make 30 variables per item using $item1_1, $item1_2... $item13_3, $item13_4 etc etc.. but a far more efficient way of playing with the data and managing it would obviously be arrays.
In my particular situation I will be using 5-7 container items (an array on their own containing Item IDs) and an array for each item itself. So basically if I have a 50 slot container, the container1 array has 51 indexes with indexes 1-50 containing itemIDs that are associated with their own array $itemxx.array that might have 30-40 indexes as well.
- When I remove an item from the inventory I reset that item.array to a single index
- When I destroy a container (IE move it) I wipe out the container array
Is this acceptable use of arrays or am I going to run into memory leak issues on the client? Anyone got any thoughts on this? Obviously flatfile text files are an option but they are slow and much more intensive to parse than a simple array call.
Am I going to get spanked you think running say 300-400 arrays?
Thanks in advance.
#2
Fortuantely, with my current design, these arrays are initialized during mission load so although there may be a performance hit it doesnt really impact the client. What I have currently running is that the player data is loaded first and then the mission load is started.
I really like some of the features of your resource and will take a closer look at it when I get some downtime. Would've been a nice resource for me to have when I started rolling this stuff together heh.
Thank you again for your feedback. it's much appreciated.
07/19/2008 (10:16 am)
Thanks so much James. Really nice to hear from someone who obviously knows a little about it :) Your suggestion about the performance hit was well noted. I had concidered actually setting a schedule with a random millisecond timer to init and call the server for item details.. Still thinking about it. I wont decide untill I have actually tested a full inventory load from the server and see how the performance is hit.Fortuantely, with my current design, these arrays are initialized during mission load so although there may be a performance hit it doesnt really impact the client. What I have currently running is that the player data is loaded first and then the mission load is started.
I really like some of the features of your resource and will take a closer look at it when I get some downtime. Would've been a nice resource for me to have when I started rolling this stuff together heh.
Thank you again for your feedback. it's much appreciated.
Associate James Ford
Sickhead Games
By the way, you might check out this resource, could have some handy methods for array manipulation. I'm open to suggests for expanding/improving it as well.
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=15077