有固定大小分配器的优雅C ++实现吗? [英] Is there an elegant C++ implementation of fixed-size allocator?

查看:57
本文介绍了有固定大小分配器的优雅C ++实现吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果必须包含的头文件的数量尽可能少,我认为C ++库是优雅的".

I think a C++ library is "elegant" if the number of header files which must be included are as less as possible.

我知道已经有固定大小的分配器,例如Loki::SmallObjectAllocatorboost::pool.尽管两者都很出色,但我认为它们并不优雅,也不容易无缝集成到项目中.

I know there have been existing fixed-size allocators like Loki::SmallObjectAllocator and boost::pool. Although both are excellent, I think they are not elegant and not easy to be seamlessly integrated into projects.

大多数时候,我只需要Boost库的一小部分,但是我必须将整个库安装在我的机器上.例如,如果我想使用boost :: pool,我希望只包含 ONE 头文件boost_pool.h即可完成工作.因为我认为固定大小的分配器不应过多地依赖于其他组件.我认为理想的代码应如下所示:

Most times, I only need a little part of boost library, but I have to install the whole library on my machine. 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. 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();
}

有没有这样的图书馆?

推荐答案

欢迎您使用我的.是否优雅,您都可以决定.但这只是一个短标头,仅依赖于几个小的标准标头.分配器满足C ++ 11分配器要求,这是C ++ 03分配器要求的子集.如果需要,可以随时添加C ++ 03样板.

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. You can always add the C++03 boiler plate if you need it.

这篇关于有固定大小分配器的优雅C ++实现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆