Hi there,
Is it possible to use a bank to store pointers to type-instances?
I'm working on a spacegame and each space-sector can have a different amount of spacestations in it.
Right now I'm using an array of types (1 dimension) to store the pointers to the Sector-type-instances and another array (2 dimensions) to hold all pointers to all spacestation type-instances.
For the second array: the first dimension holds the SectorNumber (5 Sectors), the second one holds the StationNumber (10 Stations per sector).
Actually 6 Sectors and 11 Stations, but I don't use index 0, because it's difficult as it is right now for me to keep things organised.
This code shows the current setup (only an example), because the arrays are redimmed to hold all data, which is stored in a textfile (so the size of those arrays is based on the data in that file).
But when a sector (say sector 3) only has 1 station in it, then the array DOES have 10 indexes available (which are not used at all) for that sector.
When the universe is small (like in this example), then this will not be an issue for memory-usage, but when the universe has about 150 sectors and a maximum of 25 stations per sector, then it can lead to a lot of unused memory.
And not all sectors will have those 25 stations inside it.
The most populated sector will have 25 stations (as an example, don't know yet how many it will be eventually).
I tried to include another field in the Sector-type, which hold the pointer to a bank.
After that, I've tried to assign a new Station-type-instance to this bank (after resizing it), but I got a "Illegal Type Conversion" error.
So I wanted to have each Sector-type-instance have it's own bank, which would hold all pointers to all Station-type-instances in that sector.
This could work as a linked-list of Stations per sector.
It would be sort sort of private TList (like in BMax), but then with Banks.
Then no memory is wasted, as the bank would only be as big as needed to hold all pointers.
Is this possible?
If it is possible, how can I do this?
Is it possible to use a bank to store pointers to type-instances?
I'm working on a spacegame and each space-sector can have a different amount of spacestations in it.
Right now I'm using an array of types (1 dimension) to store the pointers to the Sector-type-instances and another array (2 dimensions) to hold all pointers to all spacestation type-instances.
Type Sector Field Name$ Field ... End Type Type Station Field Name$ Field ... End Type ArraySectors.Sector(5) ArrayStations.Station(5, 10)
For the second array: the first dimension holds the SectorNumber (5 Sectors), the second one holds the StationNumber (10 Stations per sector).
Actually 6 Sectors and 11 Stations, but I don't use index 0, because it's difficult as it is right now for me to keep things organised.
This code shows the current setup (only an example), because the arrays are redimmed to hold all data, which is stored in a textfile (so the size of those arrays is based on the data in that file).
But when a sector (say sector 3) only has 1 station in it, then the array DOES have 10 indexes available (which are not used at all) for that sector.
When the universe is small (like in this example), then this will not be an issue for memory-usage, but when the universe has about 150 sectors and a maximum of 25 stations per sector, then it can lead to a lot of unused memory.
And not all sectors will have those 25 stations inside it.
The most populated sector will have 25 stations (as an example, don't know yet how many it will be eventually).
I tried to include another field in the Sector-type, which hold the pointer to a bank.
Type Sector Field Name$ Field SectorList = CreateBank(0) End Type
After that, I've tried to assign a new Station-type-instance to this bank (after resizing it), but I got a "Illegal Type Conversion" error.
So I wanted to have each Sector-type-instance have it's own bank, which would hold all pointers to all Station-type-instances in that sector.
This could work as a linked-list of Stations per sector.
It would be sort sort of private TList (like in BMax), but then with Banks.
Then no memory is wasted, as the bank would only be as big as needed to hold all pointers.
Is this possible?
If it is possible, how can I do this?