avatar
数组大小问题请教# Unix - 噫吁兮,危乎高哉
v*t
1
下面是一个简单的矩阵加法的程序,但是在VC6.0下运行矩阵大小不能超过400*400
而在学校的unix上用g++ 运行不能超过1000*1000,否则就出错。但我的账号空间足够大。
请问是什么原因?为什么只能支持这么小的矩阵?谢谢。
// Matrix.h: interface for the Matrix class.
//
//////////////////////////////////////////////////////////////////////
#define matrix_size 700 //这里的size一改成1000以上就出错
//const int matrix_size = 17000;
class Matrix
{
public:
friend Matrix &operator+(Matrix&, Matrix&);
Matrix(int);
Matrix();
~Matrix();
int element_value;
int arr[matrix_size][ma
avatar
G*T
2
maybe u need more memory

【在 v**t 的大作中提到】
: 下面是一个简单的矩阵加法的程序,但是在VC6.0下运行矩阵大小不能超过400*400
: 而在学校的unix上用g++ 运行不能超过1000*1000,否则就出错。但我的账号空间足够大。
: 请问是什么原因?为什么只能支持这么小的矩阵?谢谢。
: // Matrix.h: interface for the Matrix class.
: //
: //////////////////////////////////////////////////////////////////////
: #define matrix_size 700 //这里的size一改成1000以上就出错
: //const int matrix_size = 17000;
: class Matrix
: {

avatar
L*y
3
try pointer and dynamic allocate with new [] and delete[] within your
cons/destructor.
There might not be enough space for huge static allocation, which stays in
diffrent mem loc from dynamic one.

大。

【在 v**t 的大作中提到】
: 下面是一个简单的矩阵加法的程序,但是在VC6.0下运行矩阵大小不能超过400*400
: 而在学校的unix上用g++ 运行不能超过1000*1000,否则就出错。但我的账号空间足够大。
: 请问是什么原因?为什么只能支持这么小的矩阵?谢谢。
: // Matrix.h: interface for the Matrix class.
: //
: //////////////////////////////////////////////////////////////////////
: #define matrix_size 700 //这里的size一改成1000以上就出错
: //const int matrix_size = 17000;
: class Matrix
: {

avatar
r*a
4
栈的大小有限,如果要处理大矩阵,应该从堆里面分配内存。

大。

【在 v**t 的大作中提到】
: 下面是一个简单的矩阵加法的程序,但是在VC6.0下运行矩阵大小不能超过400*400
: 而在学校的unix上用g++ 运行不能超过1000*1000,否则就出错。但我的账号空间足够大。
: 请问是什么原因?为什么只能支持这么小的矩阵?谢谢。
: // Matrix.h: interface for the Matrix class.
: //
: //////////////////////////////////////////////////////////////////////
: #define matrix_size 700 //这里的size一改成1000以上就出错
: //const int matrix_size = 17000;
: class Matrix
: {

avatar
c*n
5
why is stack size limited?
it's just a section in the huge linear address space,
which is then paged in to physical address

【在 r**a 的大作中提到】
: 栈的大小有限,如果要处理大矩阵,应该从堆里面分配内存。
:
: 大。

avatar
r*a
6

To decrease the waste of memory, the default size of the stack cannot be too
large.

【在 c******n 的大作中提到】
: why is stack size limited?
: it's just a section in the huge linear address space,
: which is then paged in to physical address

avatar
r*a
7
你没有见过stack overflow的错误吧?呵呵

【在 c******n 的大作中提到】
: why is stack size limited?
: it's just a section in the huge linear address space,
: which is then paged in to physical address

avatar
G*T
8

use point for arr

【在 v**t 的大作中提到】
: 下面是一个简单的矩阵加法的程序,但是在VC6.0下运行矩阵大小不能超过400*400
: 而在学校的unix上用g++ 运行不能超过1000*1000,否则就出错。但我的账号空间足够大。
: 请问是什么原因?为什么只能支持这么小的矩阵?谢谢。
: // Matrix.h: interface for the Matrix class.
: //
: //////////////////////////////////////////////////////////////////////
: #define matrix_size 700 //这里的size一改成1000以上就出错
: //const int matrix_size = 17000;
: class Matrix
: {

avatar
a*e
9
important point: the default size of stack in VC is only 1Mb.
Excerpt from MSDN:
/STACK (Stack Allocations)
The Stack Allocations (/STACK:reserve[,commit]) option sets the size of the
stack in bytes.
To find this option in the development environment, click Settings on the Pr
oject menu. Then click the Link tab, and click Output in the Category box. T
he Reserve text box (or in the reserve argument on the command line) specifi
es the total stack allocation in virtual memory. The default stack

【在 v**t 的大作中提到】
: 下面是一个简单的矩阵加法的程序,但是在VC6.0下运行矩阵大小不能超过400*400
: 而在学校的unix上用g++ 运行不能超过1000*1000,否则就出错。但我的账号空间足够大。
: 请问是什么原因?为什么只能支持这么小的矩阵?谢谢。
: // Matrix.h: interface for the Matrix class.
: //
: //////////////////////////////////////////////////////////////////////
: #define matrix_size 700 //这里的size一改成1000以上就出错
: //const int matrix_size = 17000;
: class Matrix
: {

avatar
r*a
10
这个不是解决问题的根本办法,你需要事先知道你的array的大小,否则除非stack size设
得很大,还是可能会stack overflow,从堆上分配空间是最好的解决办法。

【在 a******e 的大作中提到】
: important point: the default size of stack in VC is only 1Mb.
: Excerpt from MSDN:
: /STACK (Stack Allocations)
: The Stack Allocations (/STACK:reserve[,commit]) option sets the size of the
: stack in bytes.
: To find this option in the development environment, click Settings on the Pr
: oject menu. Then click the Link tab, and click Output in the Category box. T
: he Reserve text box (or in the reserve argument on the command line) specifi
: es the total stack allocation in virtual memory. The default stack

avatar
v*t
11
我主要想做一些测试.
如果我用C的方式写的话,数组可以定得很大。以下是这个程序,我
同样用g++编译,能正常运行。但如果用我以前贴出来的Class方式的
C++程序的话,就不能超过800。我不明白差别为什么会这么大。
而且还有一个很奇怪的现象,就是同样用Class方式写的程序,有一次
我无意中运行了一下,可以超过1000。但后来加大以后,出现了segment
fault(core dump)错误以后,即使我把core删掉,还是不能超过800。
#include
#include
#define matrix_size 11000
int main(void)
{
static int a[matrix_size][matrix_size];
static int b[matrix_size][matrix_size];
static int c[matrix_size][matrix_size];
static int d[matrix_size][matrix_size];
//int i,j,v;
register

【在 r**a 的大作中提到】
: 这个不是解决问题的根本办法,你需要事先知道你的array的大小,否则除非stack size设
: 得很大,还是可能会stack overflow,从堆上分配空间是最好的解决办法。

avatar
r*a
12
对不起,但是你知道堆和栈的区别吗?如果不知道,俺也没办法,呵呵!

【在 v**t 的大作中提到】
: 我主要想做一些测试.
: 如果我用C的方式写的话,数组可以定得很大。以下是这个程序,我
: 同样用g++编译,能正常运行。但如果用我以前贴出来的Class方式的
: C++程序的话,就不能超过800。我不明白差别为什么会这么大。
: 而且还有一个很奇怪的现象,就是同样用Class方式写的程序,有一次
: 我无意中运行了一下,可以超过1000。但后来加大以后,出现了segment
: fault(core dump)错误以后,即使我把core删掉,还是不能超过800。
: #include
: #include
: #define matrix_size 11000

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。