I would recommend
const int region_size = 16; //powers of two only! 4, 8, 16, 32, 64, etc const int region_minor = region_size-1; const int region_major = ~region_minor; typedef std::array<region_size, std::array<region_size, point> > region; //a 16 by 16 region std::map<std::pair<int, int>, region> world; point& getPoint(int x, int y) { std::pair<int,int> major_coords(x®ion_major, y®ion_major); region &r = world[major_coords]; //get region return r[x®ion_minor,y®ion_minor]; //return the point in this region } //This creates points/regions as they're needed as well.
This allows infinite expansion in all dimensions (including negative, which is difficult to do with arrays) and spaces. Depending on what you are doing, you usually want to touch several points in the area at the same time, and if you have a map of points, this will be an extra overhead both in memory and in time. If you create a map of small regions, it uses less memory and time.
source share