views:

75

answers:

5

So I wanted to separate out just the smart pointers from boost to use in my project and I was guided to use bcp utility.

Today I got it compiled and did bcp smart_ptr to_copy_to_my_project/.

The result: 6MB of code in to_copy_to_my_project/ directory.

Are you kidding me? I don't want to add 6MB of header files to my 100KB project just to use smart pointers.

For example, it copies the following win32 stuff (I am on Linux):

Copying file: boost/thread/win32/basic_timed_mutex.hpp
Copying file: boost/thread/win32/condition_variable.hpp
Copying file: boost/thread/win32/interlocked_read.hpp

Why would it copy win32 stuff with smart_ptr when I am on Linux?

Also:

Copying file: boost/mpl/aux_/preprocessed/msvc60/advance_backward.hpp
...
Copying file: boost/mpl/aux_/preprocessed/msvc70/advance_backward.hpp
...
Copying file: boost/mpl/aux_/preprocessed/mwcw/advance_backward.hpp

And:

Copying file: boost/date_time/adjust_functors.hpp

Why does smart_ptr depend on date_time?

Also what about all these tests that it copied over:

Copying file: libs/smart_ptr/test/allocate_shared_esft_test.cpp
...

I don't need any of it! I just need smart_ptr!

Did I do something wrong? Why did it copy 6MB of code just for the smart pointers, which I would expect to be 10KB or 20KB...

Thanks, Boda Cydo.

A: 

You could just use the stl's shared pointer: std::tr1::shared_ptr, which for all intents and purposes "is" boost::shared_ptr.

AndreasT
But then it requires I compile my code with -std=c++0x, right?
bodacydo
A: 

I suspect that you could delete the test and win32 folders--they are probably only included when testing or on that platform. I can't speak to most of the header files, but I know smart_ptr does lots of crazy stuff so that you can convert boost::shared_ptr<Foo> into boost::shared_ptr<const Foo>, which most templates can't do. If you'd like a counting pointer that fits in only a few files, it's not hard to write one, but it won't be as nice as boost.

Since you say you're on Linux, why not just list boost as a dependency?

robert
Listing boost as a dependency is pretty scary - it's 37MB compressed and over 100MB decompressed. For my 100KB application, that's 1000 fold overhead...
bodacydo
Most Linux systems already have boost. Your small application won't be the only thing using it. Redistributing boost inside your application is wasteful.
robert
A: 

The reason being that boost supports a myriad platforms and compilers and boost modules uses other boost modules liberally. Even though most of it will be #ifdef:ed away bcp isn't smart enough to do that.

I had a similar issue so I understand your concern. I tried running the preprocessor with out platform settings then the code became significantly smaller.

In the end though we upgraded the compiler to the version that supports C++ tr1 and use std::tr1::shared_ptr.

One might argue that 6Megs are a small price to pay for industry standard smart pointers however not all developers/architects feel the same way and since I'm no despot yet I had to go with what the team decides.

FuleSnabel
A: 

bcp will copy a lot less if you do

bcp shared_ptr.hpp to_copy_to_my_project/.

It still seems like way too much, I agree.

yig
A: 

If all you want is smart_ptr and you're not interested in #define'ing BOOST_SP_USE_QUICK_ALLOCATOR (which is not defined by default), you only need:

boost/assert.hpp
boost/checked_delete.hpp
boost/config.hpp
boost/config/compiler/*
boost/config/no_tr1/functional.hpp
boost/config/no_tr1/memory.hpp
boost/config/no_tr1/utility.hpp
boost/config/platform/*
boost/config/posix_features.hpp
boost/config/select_compiler_config.hpp
boost/config/select_platform_config.hpp
boost/config/select_stdlib_config.hpp
boost/config/stdlib/*
boost/config/suffix.hpp
boost/config/user.hpp
boost/current_function.hpp
boost/detail/interlocked.hpp
boost/detail/sp_typeinfo.hpp
boost/detail/workaround.hpp
boost/enable_shared_from_this.hpp
boost/exception/detail/attribute_noreturn.hpp
boost/exception/exception.hpp
boost/memory_order.hpp
boost/non_type.hpp
boost/shared_ptr.hpp
boost/smart_ptr/*
boost/throw_exception.hpp
boost/type.hpp

This comes to 365k, with the bulk of the code actually in boost/smart_ptr. There is still a lot of code in boost/config. If you know what platforms you're targeting, you could pare down boost/config/compiler, boost/config/platform, and boost/config/stdlib. Then the vast majority of the code would be in boost/smart_ptr.

yig