为什么Boost的`bcp smart_ptr dir/`复制了6MB的源代码?
因此,我想将智能指针从 boost 中分离出来,以便在我的项目中使用,并指导我使用 bcp 实用程序。
今天我编译了它并执行了bcp smart_ptr to_copy_to_my_project/
。
结果:to_copy_to_my_project/
目录中有 6MB 的代码。
你在开玩笑吧?我不想仅仅为了使用智能指针而将 6MB 的头文件添加到我的 100KB 项目中。
例如,它复制以下 win32 内容(我在 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
当我在 Linux 上时,为什么它会使用 smart_ptr 复制 win32 内容?
另外:
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
并且:
Copying file: boost/date_time/adjust_functors.hpp
为什么 smart_ptr 依赖于 date_time?
另外,它复制的所有这些测试又如何:
Copying file: libs/smart_ptr/test/allocate_shared_esft_test.cpp
...
我不需要任何一个!我只需要 smart_ptr!
我做错了什么吗?为什么它只是为了智能指针而复制 6MB 的代码,而我预计是 10KB 或 20KB...
谢谢,Boda Cydo。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想要的只是
smart_ptr
并且您对#define
'ingBOOST_SP_USE_QUICK_ALLOCATOR
(默认情况下未定义)不感兴趣,您只需需要:这达到了 365k,大部分代码实际上在
boost/smart_ptr
中。boost/config
中还有很多代码。如果您知道目标平台,则可以减少boost/config/compiler
、boost/config/platform
和boost/config/stdlib< /代码>。那么绝大多数代码将位于
boost/smart_ptr
中。If all you want is
smart_ptr
and you're not interested in#define
'ingBOOST_SP_USE_QUICK_ALLOCATOR
(which is not defined by default), you only need:This comes to 365k, with the bulk of the code actually in
boost/smart_ptr
. There is still a lot of code inboost/config
. If you know what platforms you're targeting, you could pare downboost/config/compiler
,boost/config/platform
, andboost/config/stdlib
. Then the vast majority of the code would be inboost/smart_ptr
.您可以只使用 stl 的共享指针:
std::tr1::shared_ptr
,从所有意图和目的来看,“是”boost::shared_ptr
。You could just use the stl's shared pointer:
std::tr1::shared_ptr
, which for all intents and purposes "is"boost::shared_ptr
.我怀疑您可以删除 test 和 win32 文件夹 - 它们可能仅在测试时或在该平台上包含。我无法谈论大多数头文件,但我知道 smart_ptr 做了很多疯狂的事情,以便您可以将 boost::shared_ptr;进入 boost::shared_ptr,这是大多数模板无法做到的。如果您想要一个只适合几个文件的计数指针,那么编写一个并不难,但它不会像 boost 那样好。
既然你说你在 Linux 上,为什么不直接将 boost 列为依赖项呢?
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?
原因是 boost 支持无数的平台和编译器,并且 boost 模块可以自由地使用其他 boost 模块。尽管大部分内容都会被 #ifdef:ed 掉,但 bcp 还不够聪明,无法做到这一点。
我遇到了类似的问题,所以我理解你的担忧。我尝试在没有平台设置的情况下运行预处理器,然后代码变得明显更小。
最后我们将编译器升级到支持C++ tr1的版本并使用std::tr1::shared_ptr。
有人可能会说 6Megs 对于行业标准智能指针来说只是一个很小的代价,但并非所有开发人员/架构师都有同样的感觉,而且由于我不是专制者,但我必须遵循团队的决定。
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.
如果你这样做,
bcp
的复制量会少很多,我同意,它看起来仍然太多了。
bcp
will copy a lot less if you doIt still seems like way too much, I agree.