【发布时间】:2014-10-08 22:17:03
【问题描述】:
例如,有一个包含数千个元素的 int 数组:
static int st_indices[9999] = {
0, 27, 26, 1, 41, 71, 0, 26, 101, 0, 101, 131, 0, 131, 72,
1, 71, 176, 2, 56, 206, 3, 116, 236, 4, 146, 266, 5, 161, 296,
......
};
和
int* dy_indices = new int[9999] {
0, 27, 26, 1, 41, 71, 0, 26, 101, 0, 101, 131, 0, 131, 72,
1, 71, 176, 2, 56, 206, 3, 116, 236, 4, 146, 266, 5, 161, 296,
......
};
以上两种方式有什么区别,尤其是花括号中的值对内存使用的影响?
我知道 st_indices 将一直存在于内存中,直到程序结束 (STACK),而 dy_indices 将在 delete [](HEAP) 之后释放。还是关于堆栈与 .DATA 段的问题?
【问题讨论】:
标签: arrays c++11 memory-management memory-segmentation