Results 1 to 3 of 3

Thread: Memory Problems...

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2004
    Posts
    14

    Angry 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:
    1. Public Type tPosition
    2.     SolarNumber As Long
    3.     SolarName As String
    4.     SolarSystemInfo As String
    5.     PlanetNumber As Long
    6.     PlanetName As String
    7.     PlanetInflation As Long               'Should always be a percent. 0.05 for 5%
    8.     PlanetInfo As String
    9.     CityNumber As Long
    10.     CityName As String
    11.     CityInfo As String
    12.     CityWeather As String
    13.     CityInventoryNumber(1000) As Long
    14.     CityInventoryName(1000) As String
    15.     CityInventoryAmount(1000) As Long
    16. End Type
    17. 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:
    1. 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.

  2. #2
    Frenzied Member ae_jester's Avatar
    Join Date
    Jun 2001
    Location
    Kitchener Ontario Canada Earth
    Posts
    1,545
    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:
    1. Private Type InventoryItemType
    2.     CityInventoryNumber As Long
    3.     CityInventoryName As String
    4.     CityInventoryAmount As Long
    5. End Type
    6.  
    7. Private Type CityType
    8.     CityNumber As Long
    9.     CityName As String
    10.     CityInfo As String
    11.     CityWeather As String
    12.     InventoryItems() As InventoryItemType
    13. End Type
    14.  
    15. Private Type PlanetType
    16.     PlanetNumber as Long
    17.     PlanetName as String
    18.     PlanetInflation As Long
    19.     PlanetInfo As String
    20.     Cities() as CityType
    21. End Type
    22.  
    23. Private Type SolarSystemType
    24.     SolarNumber As Long
    25.     SolarName as String
    26.     SolarSystemInfo As String
    27.     Planets() as PlanetType
    28. End Type
    29.  
    30. Private SolarSystems() As SolarSystemType
    Last edited by ae_jester; Jun 5th, 2004 at 05:14 PM.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654
    Simplifying would do good. You could have just something like:

    VB Code:
    1. Type MySolarSystem
    2.     Name As String
    3.     X1 As Long 'top left corner in the map this solar system starts
    4.     Y1 As Long
    5.     X2 As Long 'top right corner
    6.     Y2 As Long
    7.     X3 As Long 'bottom left
    8.     Y3 As Long
    9.     X4 As Long 'bottom right
    10.     Y4 As Long
    11.     'you can simplify the position by having rectangular areas...
    12. End Type
    13.  
    14. Type MyPlanet
    15.     Name As String
    16.     Info As String
    17.     X As Long 'position in the solar system
    18.     Y As Long 'solar system is determined by the X and Y values
    19.     Inflation As Single 'can hold decimals unlike Long
    20. End Type
    21.  
    22. Type MyCity
    23.     Planet As Integer 'index to Planets array
    24.     Name As String
    25.     Info As String
    26.     Weather As Byte 'you can have 256 different weathers this way
    27.     Inventory(999) As Integer 'you can have 1000 different item types this way
    28. End Type
    29.  
    30. Public Solars() As MySolarSystem, Planets() As MyPlanet, Cities() As MyCity
    31.  
    32. 'just some random example...
    33. Sub Initialize()
    34.     ReDim Solars(9)
    35.     ReDim Planets(49)
    36.     ReDim Cities(499)
    37. 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
  •  



Click Here to Expand Forum to Full Width