2 questions for my map array

Started by
3 comments, last by Wiggin 17 years, 8 months ago
I have a couple of questions for my map array. Is a list of pointers to objects considerably smaller or faster than a list of objects? Does it make a difference if most of the objects are the same? Is it horribly inefficient to not load textures all at once and access them as needed, but rather to load them when needed and destroy them afterward? (I'm guessing yes...)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~I program in C++, on MSVC++ '05 Express, and on Windows. Most of my programs are also for windows.
Advertisement
A list of pointers uses more memory than a list of objects, since you have to store the objects somewhere either way, but with the list of pointers you also have to store pointers.
It's fine to load textures on an as needed basis, but keep them around for a set amount of time afterwards, and reset that time when they get used again, so that those that are constantly being used stay in memory.
Quote:Is a list of pointers to objects considerably smaller or faster than a list of objects? Does it make a difference if most of the objects are the same?


Uhh... it depends on what you mean by "the same."

Let's say your map array is a 2D array of locations for a 2D wargame. Let's say each location can hold a variable number of "Soldier" objects. You might then choose to let each location have a list<Soldier*> member. Since most of the locations are likely to be empty of soldiers, most of your objects will be "the same." However, you won't be able to save space by storing all these identical location objects as pointers to a single object, because then if one of them were to receive a soldier, they all would.

On the other hand, if the location objects don't have a dynamic list of content, but just have a lot of static data like type of terrain, texture, isPassable attributes and so on, then once again you'll have a lot of identical objects, and in this case you can save massive amounts of space by storing the map as pointers to terrain type objects instead of a large array of terrain objects.
So what you're saying is that, since my map array is a 2D array of lists of map_tile objects, I'd do better to make it a 2D array of lists of pointers to map_tile objects, since map_tile doesn't contain any arrays or lists or anything. Correct?

I like that "keep them for a certain amount of time" idea for the textures. This ensures that if I'm not using a texture, it's not loaded. A very good idea.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~I program in C++, on MSVC++ '05 Express, and on Windows. Most of my programs are also for windows.
Quote:So what you're saying is that, since my map array is a 2D array of lists of map_tile objects, I'd do better to make it a 2D array of lists of pointers to map_tile objects, since map_tile doesn't contain any arrays or lists or anything. Correct?


Yeah, but it's difficult to say anything for certain without knowing the details of your application. I mean, if your static map_tile objects happen to have 32 isPassable booleans, one for each of the 32 types of soldiers you happen to have, that suddenly means that using pointers, you'll need to create 2^32 map_tile objects, not a very nice prospect. In this case, you would want to just store the objects themselves in the array.

By the way, why are you doing a 2D array of lists of pointers? Why not just a 2D array of pointers? Are you stacking tiles on top of each other, like, say, road tiles on top of grass tiles?

This topic is closed to new replies.

Advertisement