|
-
Jun 5th, 2004, 04:29 PM
#1
Thread Starter
New Member
Memory Problems...
I'm makin a game and I have a lot of things that are being stored. Well I am using arrays to store information, actually I'm using types that have arrays. Example:
VB Code:
Public Type tPosition
SolarNumber As Long
SolarName As String
SolarSystemInfo As String
PlanetNumber As Long
PlanetName As String
PlanetInflation As Long 'Should always be a percent. 0.05 for 5%
PlanetInfo As String
CityNumber As Long
CityName As String
CityInfo As String
CityWeather As String
CityInventoryNumber(1000) As Long
CityInventoryName(1000) As String
CityInventoryAmount(1000) As Long
End Type
Global Position(1000, 1000, 1000) As tPosition
Well as you can see, that's a lot of information.... Well I have a crap load more types like this; but not with the (1000, 1000, 1000) arrray.. Main just one set of 1000..... Now, I need to know if there is any other way to store large amounts of code like this. Without hogging memory. Or should I have the positions set like this?
VB Code:
SolarSystem(12).Planet(3).City(400).Name = "Akron"
I am lost. I've never had to work with this amount of arrays and information that is going to be stored... I am open to any suggestions. Thanks in advanced.
By the way; it won't even let me do Position(10, 10, 10)
Eat a beaver, save a tree.
-
Jun 5th, 2004, 05:07 PM
#2
Frenzied Member
I'm not experienced in this type of stuff but I do notice a problem
Your array (1000, 1000, 1000) is basically declaring a BILLION array slots each of which contains THOUSANDS and THOUSANDS of bytes of data. That will chew up all available memory in a split second.
I think it's fair to say that you don't have a city at every single one of these coordinates. In that case, why don't you just store the data for those coordinates that do have a city?
As I said, I'm not really sure what you are trying to store so it's hard for me to guess how to improve it. Maybe try to explain what that thing is really trying to store and why.
BTW, your line...
SolarSystem(12).Planet(3).City(400).Name = "Akron"
makes a lot more sense to me.
If that's what you wanted to do, you can do it like this...
VB Code:
Private Type InventoryItemType
CityInventoryNumber As Long
CityInventoryName As String
CityInventoryAmount As Long
End Type
Private Type CityType
CityNumber As Long
CityName As String
CityInfo As String
CityWeather As String
InventoryItems() As InventoryItemType
End Type
Private Type PlanetType
PlanetNumber as Long
PlanetName as String
PlanetInflation As Long
PlanetInfo As String
Cities() as CityType
End Type
Private Type SolarSystemType
SolarNumber As Long
SolarName as String
SolarSystemInfo As String
Planets() as PlanetType
End Type
Private SolarSystems() As SolarSystemType
Last edited by ae_jester; Jun 5th, 2004 at 05:14 PM.
-
Jun 5th, 2004, 05:22 PM
#3
Simplifying would do good. You could have just something like:
VB Code:
Type MySolarSystem
Name As String
X1 As Long 'top left corner in the map this solar system starts
Y1 As Long
X2 As Long 'top right corner
Y2 As Long
X3 As Long 'bottom left
Y3 As Long
X4 As Long 'bottom right
Y4 As Long
'you can simplify the position by having rectangular areas...
End Type
Type MyPlanet
Name As String
Info As String
X As Long 'position in the solar system
Y As Long 'solar system is determined by the X and Y values
Inflation As Single 'can hold decimals unlike Long
End Type
Type MyCity
Planet As Integer 'index to Planets array
Name As String
Info As String
Weather As Byte 'you can have 256 different weathers this way
Inventory(999) As Integer 'you can have 1000 different item types this way
End Type
Public Solars() As MySolarSystem, Planets() As MyPlanet, Cities() As MyCity
'just some random example...
Sub Initialize()
ReDim Solars(9)
ReDim Planets(49)
ReDim Cities(499)
End Sub
A lot depends on how big, configurable and random you want your world to be. The bigger the world, the more data it requires. What I've shown here is pretty much as low memory use you can get with your project. Good luck!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|