I'm developing an emulator for a game. I have an object named "Map", which contains the map's id, and other various information about it. The game contains a lot of map objects (about 10,000). The data is located inside a SQL table, so I'm using that to load it.
I have a class named CachedMaps
which inherits from a KeyedCollection
of int and map. The identifier is the map's id. Unfortunately, it takes about 5 seconds to load all the maps.
Not all the maps will be visited, anyway. My friend suggested that I would use "lazy loading", I'm not sure how to do it - like, load the map's data or object only when a user enters it. How is it possible? Thank you.
public class CachedMaps : KeyedCollection<int, Map>
{
public CachedMaps()
: base()
{
// The loading code.
// this.Add(new Map(....));
}
}