简体   繁体   English

有固定大小分配器的优雅C ++实现吗?

[英]Is there an elegant C++ implementation of fixed-size allocator?

I think a C++ library is "elegant" if the number of header files which must be included are as less as possible. 我认为,如果必须包含的头文件的数量尽可能少,则C ++库是“优雅的”。

I know there have been existing fixed-size allocators like Loki::SmallObjectAllocator and boost::pool . 我知道已经有固定大小的分配器,如Loki::SmallObjectAllocatorboost::pool Although both are excellent, I think they are not elegant and not easy to be seamlessly integrated into projects. 尽管两者都很出色,但我认为它们并不优雅,也不容易无缝集成到项目中。

Most times, I only need a little part of boost library, but I have to install the whole library on my machine. 大多数时候,我只需要Boost库的一小部分,但是我必须在机器上安装整个库。 For example, if I want to use boost::pool, I hope to just include ONE header file boost_pool.h and the work is done. 例如,如果我想使用boost :: pool,我希望只包含一个头文件boost_pool.h完成工作。 Because I think a fixed-size allocator should not be so dependent on too many other components. 因为我认为固定大小的分配器不应过多地依赖于其他组件。 In my opinion, ideal code should look like the following: 我认为理想的代码应如下所示:

#include <boost_pool.h>

int main()
{
   boost::pool<int> p;
   int* v = p.allocate();
}

Does there exist such a library? 有没有这样的图书馆?

You are welcome to mine . 欢迎您来我的 Whether it is elegant or not, you can decide. 是否优雅,都可以决定。 But it is just one short header dependent upon just a couple of small standard headers. 但这只是一个短头,仅依赖于几个小的标准头。 The allocator meets the C++11 allocator requirements, which are a subset of the C++03 allocator requirements. 分配器满足C ++ 11分配器要求,这是C ++ 03分配器要求的子集。 You can always add the C++03 boiler plate if you need it. 如果需要,您总是可以添加C ++ 03样板。

Are you using GCC? 您在使用GCC吗? It's standard library comes with a few fixed-size allocators as extensions, see http://gcc.gnu.org/onlinedocs/libstdc++/manual/memory.html#allocator.ext 它的标准库带有一些固定大小的分配器作为扩展,请参阅http://gcc.gnu.org/onlinedocs/libstdc++/manual/memory.html#allocator.ext

They're fairly standalone (not sure about elegant, it's a long time since I looked at their code properly) 它们是相当独立的(不确定优雅,自从我正确地看了他们的代码以来已经有很长时间了)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM