small string optimization for vector?(向量的小字符串优化?)
问题描述
我知道有几个(全部?)STL 实现实现了小字符串"优化,而不是存储通常的 3 个用于开始、结束和容量的指针,字符串将在用于指针的内存中存储实际字符数据,如果 sizeof(字符)<= sizeof(指针).我处于一种情况,我有很多元素大小 <= sizeof(pointer) 的小向量.我不能使用固定大小的数组,因为向量需要能够动态调整大小并且可能会变得非常大.但是,向量的中位数(不是平均值)大小仅为 4-12 字节.因此,适用于向量的小字符串"优化对我来说非常有用.这样的事情存在吗?
I know several (all?) STL implementations implement a "small string" optimization where instead of storing the usual 3 pointers for begin, end and capacity a string will store the actual character data in the memory used for the pointers if sizeof(characters) <= sizeof(pointers). I am in a situation where I have lots of small vectors with an element size <= sizeof(pointer). I cannot use fixed size arrays, since the vectors need to be able to resize dynamically and may potentially grow quite large. However, the median (not mean) size of the vectors will only be 4-12 bytes. So a "small string" optimization adapted to vectors would be quite useful to me. Does such a thing exist?
我正在考虑通过简单地将向量转换为字符串来滚动我自己的,即为字符串提供向量接口.好主意?
I'm thinking about rolling my own by simply brute force converting a vector to a string, i.e. providing a vector interface to a string. Good idea?
推荐答案
你可以借用 SmallVector 来自 LLVM 的实现.(仅标头,位于 LLVMincludellvmADT)
You can borrow the SmallVector implementation from LLVM. (header only, located in LLVMincludellvmADT)
这篇关于向量的小字符串优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:向量的小字符串优化?
基础教程推荐
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01