Jump to content
  • Advertisement
Sign in to follow this  
EmrldDrgn

2 questions for my map array

This topic is 4491 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...)

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!