Jump to content
  • Advertisement
Sign in to follow this  
Angelic Ice

Refering to Unique Pointer's Content

This topic is 631 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

Hey forum!

 

I want to create a data structure that simply refers to the location of unique pointers.

 

While I could use shared pointers, it feels like an overkill.

At the moment, I use raw pointers for this case, leaving me with a bad taste.

 

The data structures I use:

-A vector of unique pointers to a game element

-Data structures of raw pointers to parts of that vector

 

Changing my game elements to shared pointer just that I can refer to them feels a bit overkill.

But maybe I'm all wrong.

 

Are there any other ways of dealing with this?

Share this post


Link to post
Share on other sites
Advertisement
I don't see anything particularly wrong with using raw pointers, as long as you can be sure that the object will exist for as long as you need it to.

In some cases I find that it's preferable to use indices to the array that owns the objects (you can give these indices their own type, like GameObjectID). But I don't think this going to be particularly useful in this case.

Share this post


Link to post
Share on other sites

tl;dr third post, but if you're taking pointers to vector members you better not add anything new to the vector.

 

Nvm, you're talking about getting the addresses from the u_ps in the vector, which is fine, provided that you can guarantee that the lifetime of the u_ps exceeds that of the raw pointers.

 

Also, just to make sure, is it a vector of pointers because of polymorphism?

Edited by Khatharr

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!