是boost::container::string连续的内存
Is the memory of boost::container::string contiguous?
在c++98中,std::string的内存(c++11要求它是连续的)可能不是连续存储,那么boost::container::string呢?它保证内存是连续的吗?
如果它是连续的,它可以更自然地与遗留api一起工作。
boost::container::string str("some data ");
old_api(&str[0]);
不需要再复制到vector
boost::container::string str("some data ");
std::vector<char> buffer(str.begin(), str.end());
old_api(&str[0]);
谢谢
是,boost::containter::string
内存是连续的。
除非您使用一些非普通reference
, const_refeference
和pointer
类型的时髦分配器,否则任何boost::container::basic_string
专门化都具有连续内存。
查看string的data()
方法:它保证(无条件的)常数时间,并且每个i
对应[0
, size()
]中的data()+i == &operator[](i)
。
相关文章:
- 当需要超过16GB的连续内存时,内存分配失败
- C++,您能否设计一种数据结构,将指针保存在连续内存中并且不会使它们失效?
- 向量的内存位置不连续
- std::set 是否将对象连续存储在内存中?
- vector是否为std::移动的对象连续分配内存
- 使用连续内存实现多态性
- 我可以使用哪种数据结构来释放连续内存中的内存?
- C++将shared_ptr用于连续分配的内存
- std::array与C样式数组用于连续内存
- 在内存中连续分配的多维数组的实现
- 如何创建非 POD 类型的连续内存池?
- 为什么动态分配的两个变量的内存位置不是连续的?
- C++ 中连续内存中的模板化不同大小的结构
- POD 结构(相同类型的成员):成员是否位于连续的内存位置?
- 如何防止连续使用"new"时分配失败时内存泄漏
- 将不相邻的内存缓冲区视为连续缓冲区的数据结构
- 连续内存分配
- C/C++ Windows 或 Linux 将随机内存块映射成连续的顺序
- 如何使用 std::vector<std::tuple<A,B>> 来管理内存(调整大小、保留,...),但实际上将 As 保留在 B 之前,连续
- 将自旋锁与O(1)非内存连续代码一起使用可以吗