本文介绍了堆栈溢出的大阵,但不与同样大的载体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天我遇到了一个有趣的问题,大数据结构的工作。我最初是用一个向量来存储向上1000000整数,但后来我决定(一旦它被宣布反正我是保留百万点)实际上并没有需要载体的动态功能,这将是有益的,相反,能够在数据结构中添加值的任何地方。所以我把它切换到一个数组和 BAM 的堆栈溢出。我猜这是因为在编译时声明数组的大小将其放在堆栈并利用动态矢量,而不是把它放在堆(我猜是大?)。

那么,什么是正确的答案吗?回迁动态内存系统,这样它就会提上堆?增加堆栈的大小?还是我放​​在这里整个事情...?

大错特错

谢谢!


解决方案

Good idea.

Not such a good idea. You did need it.

I don't follow.

Much. The call stack is typically of the order of 1MB-2MB in size by default. Your "heap" (free store) is only really bounded by your available RAM.

Yes.

[edit: Joachim's right — static is another possible answer.]

You could but even if you could stretch 4MB out of it, you've left yourself no wiggle room for other local data variables. Best use dynamic memory — that's the appropriate thing to do.

No.

这篇关于堆栈溢出的大阵,但不与同样大的载体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 07:55
查看更多