Sign in to follow this  
prchakal

Questions about boost, vector and pointers

Recommended Posts

Hi,

Im making a small game and now im refactoring some things on it.

I have some questions:

1 - I have a vector that store pointers to all enemies objects. So, if using "boost::shared_ptr" to create the pointers insted of tradicional method, when i remove the pointer from the vector using the "erase" method, the pointer/object will be deleted/destroyed from memory?

2 - To use "boost::shared_ptr" i need add some library on my project, or only the include "#include "boost/shared_ptr.hpp"" is necessary?

3 - I have compiled the boost library using the tool "bootstrap.bat", it generate some ".lib" files for only some packages (like filesystem, datetime, ...), why it? This is because only this packages need include the library (".lib") file in my project, and the other only need the header?

4 - When i compiled the "boost", it generate a directory called "stage" and other "bin", what is the correct directory to take my library files (".lib")?

5 - When i compiled the "boost", what is the correct library name for release, debug, static ? It generate too many files for the same package.

Share this post


Link to post
Share on other sites
Quote:
Original post by prchakal
1 - I have a vector that store pointers to all enemies objects. So, if using "boost::shared_ptr" to create the pointers insted of tradicional method, when i remove the pointer from the vector using the "erase" method, the pointer/object will be deleted/destroyed from memory?

Correct. Or more precisely, when the last copy of a given shared_ptr is destroyed, the associated raw pointer is deleted. If you have any existing copies of the shared_ptr that aren't in the vector, the raw pointer won't be deleted (just yet).

Quote:

2 - To use "boost::shared_ptr" i need add some library on my project, or only the include "#include "boost/shared_ptr.hpp"" is necessary?

You do not need to link a library in to your binaries in order to use boost::shared_ptr.

Quote:

3 - I have compiled the boost library using the tool "bootstrap.bat", it generate some ".lib" files for only some packages (like filesystem, datetime, ...), why it? This is because only this packages need include the library (".lib") file in my project, and the other only need the header?

The documentation for each library will typically state if any libraries actually need to be created. Many libraries in boost are indeed "header-only", though.

Quote:

4 - When i compiled the "boost", it generate a directory called "stage" and other "bin", what is the correct directory to take my library files (".lib")?

Probably bin, but you should read the build instructions to be sure. Somebody else might chip in with a more definitive answer.

Quote:

5 - When i compiled the "boost", what is the correct library name for release, debug, static ? It generate too many files for the same package.

It depends on which runtime you're linking against (assuming you're using Visual C++ on Windows). Again, that's in the boost documentation.

BoostPro consulting also distribute pre-compiled libraries for Visual C++. That might be an easier option.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this