问题标签 [boost-container]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - Boost Container vector 可以通过非原始指针管理内存吗?
我有一个类似指针的结构来代替指针。与指针的不同之处在于它具有(也是特殊的)分配器可以用来释放内存的额外信息。
这种类似指针的结构适用于所有基本用途。我可以分配和取消分配内存、取消引用、递增->
等。
现在我想使用这个指针由一个类似 STL 的容器管理。早些时候,我意识到 STL 向量基本上无法处理非原始指针。
T*
编码太硬了,标准基本上排除了任何不是指针的东西。
受到 Boost.Interprocess' 的启发,offset_ptr<T>
我决定使用 Boost.Container vector
,它非常可定制,原则上可以管理任何东西,传递给它的分配器boost::container::vector
可以处理任何类似指针的东西。
现在班级boost::container::vector<T, myallocator_with_special_pointer<T>>
可以做任何事情......除了resize()
!
查看代码,boost/container/vector.hpp
似乎调整大小的过程(基本上是分配,然后是复制(或移动)和释放)涉及原始指针。
违规行是:
紧随其后的是
这两行绝对消除了使用任何不是raw_pointer
. 即使我有一个原始指针的转换运算符,有关特殊指针的其他信息也会丢失。
这个小细节禁止使用非原始指针似乎很愚蠢。考虑到容器的通用性(例如定义pointer
typedef),为什么这部分代码T*
仅用于调整大小?
换句话说,为什么 Boost Container 不使用这一行来代替
是否有解决方法或替代方法来使用 Boost Container 向量来处理非原始指针?
Boost.Container 在其手册页中说http://www.boost.org/doc/libs/1_64_0/doc/html/container/history_and_reasons.html#container.history_and_reasons.Why_boost_container
Boost.Container 是 2004 年从实验性 Shmem 库开始的长期开发工作的产物,该库率先在共享内存中使用标准容器。Shmem 包含经过修改的 SGI STL 容器代码,经过调整以支持非原始
allocator::pointer
类型和有状态分配器。经过审查,Shmem 被接受为 Boost.Interprocess,并且该库继续完善和改进这些容器。
当前的实现(在调整大小的上下文中)违背了这个设计目标。
我在这里问了一个不太具体的问题,关于分配器的其他特征:是否仍然可以自定义 STL 向量的“引用”类型?
作为参考,指定特殊指针(传播到容器)的分配器是这样的,
c++11 - 在两个不同的连续容器之间移动
我有一个std::vector<double>
我必须移动到一个boost::container::flat_set<double>
。两个容器都是连续的,因此原则上对向量进行排序后,我可以将数据从一个容器移动到另一个容器。
有没有办法在这两个不同的容器之间移动整个数据?
请考虑到我想移动整个数据,而不是逐个元素。
我可以在相同类型的容器之间移动数据,但不能在不同容器之间移动。
似乎要使它起作用,flat_set
应该有一个来自容器的移动构造函数.data()
,其中指针是从参数中窃取的。
c++ - boost::container::allocator_traits::is_partially_propagable 是什么意思?
当我遇到 boost::container::allocator_traits::is_partially_propagable 时,我试图理解boost::container::allocator_traits 。
我在网上找不到任何其他关于它的文档,我可以理解 boost::container::allocator_traits 的所有其他成员,除了 is_partially_propagable 和 storage_is_unpropagable。
编辑:
以及,它们是如何实现的以及在编写容器时如何使用它们?
c++ - gcc compile error "binding ‘const s’ to reference of type ‘s&’ discards qualifiers" when using boost::container::static_vector in other container
When using boost::container::static_vector in another container such as std::vector, gcc is returning a compile error. The following test case reproduces the error:
Complied with g++ template_test2.cpp
on Ubuntu Xenial results in the following error:
This error only occurs if struct s
contains a static vector. What is the cause of this error, and is there a workaround available?
c++ - 地图插入不明确
我正在尝试使用 boost::container::map
. 在插入数据期间,显示错误“插入不明确”。
boost - Boost.Container `dlmalloc` 和 `jemalloc`
我已经将 Boost.Container 引入我的项目中,它jemalloc
用作默认分配器,看起来像 Boots.Container 使用自定义分配器,dlmalloc
当然,在链接时我在“多重定义”链接错误上失败,因为两个“XXXalloc”被引入目标文件。关闭“jemalloc”不是一种选择,但我找不到是否可以关闭dlmalloc
使用。知道如何解决这个问题吗?
c++ - boost flat_map 批量插入
我有一个维护 boost::flat_map 的 C++ 程序。它以(key,value)的形式接收实时命令。如果 value 为 0,则 flat_map[key] 如果存在则应删除。如果 value 不为零,则如果条目已存在,则 flat_map[key] 应设置为 flat_map 中的 value,如果条目不存在则应将其插入。
但是,命令并不是一一来的。相反,它们是分批出现的,程序只需要在处理完每批命令后对 flat_map 进行排序。在处理一批命令的过程中,它不需要对 flat_map 进行排序。
鉴于这种灵活性,有没有办法通过避免在每次插入/删除时移动许多元素的 flat_map 开销来减少处理时间,并且只在每批结束时产生一次开销?该程序对延迟非常敏感。
感谢您的任何意见!