boost multi_array使用中的疑问

碧空星尘 2005-09-28 09:17:31
在我以前的应用中,我用 vector<vector<string> >来保存我数据库查询的结果集,后来感觉在使用中耗费内存挺厉害的,于是想用multi_array试试。从文档和例程上看,multi_array是使用连续地址空间的,因此对他能否保存string类型数据保持怀疑。做了个简单的测试:
-------------------------------------------
#include <iostream>
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
using namespace std;

int main () {
// Create a 3D array that is 3 x 4 x 2
typedef boost::multi_array<string, 3> array;
int x=2;
int y=4;
int z=2;
array A(boost::extents[x][y][z]);
// Assign a value to an element in the array
A[0][0][0] = "asjdfasf";
A[1][2][0] = "23412352154eeeeeee88";
cout<<A[0][0][0]<<endl;
cout<<A[1][2][0]<<endl;
return boost::exit_success;
}
-------------------------------------
竟然可以。所以考虑使用boost::multi_array<string, 2>来代替vector<vector<string> >。但是使用vector可以很方便的使用push_back增加元素,不知道multi_array有没有提供类似的功能?我感觉好像multi_array都是要自己给定大小的
...全文
108 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
snipersun 2006-06-15
  • 打赏
  • 举报
回复
这东西好像不是动态大小的

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧