问题描述
我知道有几个(全部?)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)
这篇关于向量的小字符串优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)