我的记忆力还不够吗? [英] Is my memory is not enough?

查看:40
本文介绍了我的记忆力还不够吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的成员:


我在C编程。我声明如下,但在运行程序时,

出现致命错误:

加倍[255] [255];

双b [255] [255];

当我将其更改为


加倍[255] [255];

双b [255] [100];

然后它可以工作。


我认为内存耗尽导致的问题。


但是我想知道为什么我使用malloc函数,没有错误:

------------------------

double ** a;

double ** b;


a = malloc(255 * 255 * sizeof(double));

if(a == NULL)

printf(有错误);

b = malloc(255 * 255 * sizeof(double));

if(a == NULL)

printf(有错误);

------------------------ -

我想我对这两个版本都使用相同的内存量。为什么在

第一种情况下,内存不足,而在另一种情况下,

足够大。


还有一件事,我需要使用2D数组。我尝试以下但是当我尝试访问2D数组的元素时,
总是出错:

double ** a;

double ** b;


a = malloc(255 * 255 * sizeof(double));

if(a == NULL)

printf(有错误);

b = malloc(255 * 255 * sizeof(double));

if(a == NULL )

printf(有错误);


a [1] [1] = 1;< -----错误发生

请看看并为我指出错误。或者你可以请

建议我使用其他更有效的2D阵列方法吗?


非常感谢你,期待你的回答。

SIncerly你的

Dear members:

I am programming in C. I declare as follows but when running program,
there is a fatal error appear:
double a[255][255];
double b[255][255];
When I change it to

double a[255][255];
double b[255][100];
then it works.

I think the problem caused by the running out of memory.

But I am wondering why I use malloc function, there is no error:
------------------------
double **a;
double **b;

a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
-------------------------
I think I am using the same volume of memory for both version. Why in
the first case, the memory is insufficient of memory and in the other,
it is big enough.

One more thing, I need to use 2D array. I try the following but there
is always error when I try to access to an element of the 2D array:
double **a;
double **b;

a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");

a[1][1]=1;<----- the error occurs
Pleas take a look and point out the error for me. or can you please
suggest me other more effective methods to use 2D array?

Thank you very much and look forward to your answer.
SIncerly yours

推荐答案

ch ************* @ yahoo.com 写道:
ch*************@yahoo.com wrote:
我在C编程
我声明如下,但在运行程序时,
会出现致命错误:

double a [255] [255];
double b [255] [255];

当我把它更改为

加倍[255] [255];
双b [255] [100];

然后就行了。

我认为内存耗尽导致的问题。
limit stacksize
stacksize 10240 kbytes limit stacksize unlimited
limit stacksize
stacksize unlimited uname
I am programming in C.
I declare as follows but when running program,
there is a fatal error appear:

double a[255][255];
double b[255][255];

When I change it to

double a[255][255];
double b[255][100];

then it works.

I think the problem caused by the running out of memory. limit stacksize stacksize 10240 kbytes limit stacksize unlimited
limit stacksize stacksize unlimited uname



Linux


Linux


罗伯特你好,你什么意思?请你转发你的答案。

谢谢/

Hello Robert, what do you mean? can you please repost your answer.
Thanks/



ch ************* @ yahoo.com 写道:
亲爱的成员:

我在C编程。我声明如下,但在运行程序时,
会出现致命错误:

double a [255] [ 255];
双b [255] [255];

当我把它更改为

加倍[255] [255];
双b [255] [100];

然后它可以工作。

我认为由于内存不足引起的问题。

但是我想知道为什么我使用malloc函数,没有错误:
------------------------
double ** a ;
双** b;

a = malloc(255 * 255 * sizeof(double));
if(a == NULL)
printf(" ;有错误);
b = malloc(255 * 255 * sizeof(double));
if(a == NULL)
printf(有错误) );
-------------------------

我想我为这两个版本使用相同的内存量。为什么在第一种情况下,内存不足,内存和
其他,它足够大。

还有一件事,我需要使用2D数组。我尝试以下但是当我尝试访问2D数组的元素时,
总是出错:

double ** a;
double ** b;

a = malloc(255 * 255 * sizeof(double));
if(a == NULL)
printf(有错误);
b = malloc(255 * 255 * sizeof(double));
if(a == NULL)
printf(有错误);

1] [1] = 1;< -----发生错误
Dear members:

I am programming in C. I declare as follows but when running program,
there is a fatal error appear:
double a[255][255];
double b[255][255];
When I change it to

double a[255][255];
double b[255][100];
then it works.

I think the problem caused by the running out of memory.

But I am wondering why I use malloc function, there is no error:
------------------------
double **a;
double **b;

a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
-------------------------
I think I am using the same volume of memory for both version. Why in
the first case, the memory is insufficient of memory and in the other, it is big enough.

One more thing, I need to use 2D array. I try the following but there
is always error when I try to access to an element of the 2D array:
double **a;
double **b;

a=malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");
b= malloc(255*255*sizeof(double));
if(a==NULL)
printf("there is an error");

a[1][1]=1;<----- the error occurs




声明a和b这样的


double * a [255];

double * b [255];

你必须声明一个& b作为255个双精度数组的指针,否则,
,编译器将如何知道跳过多少?当你

双重引用时。我给你一个非常简单的答案(我认为

你是新手)。阅读c.l.c常见问题解答将有助于您更好地理解这些概念。现在,您只需更改声明以匹配上面的内容即可开始使用您的

程序。


请参阅: http://www.eskimo.com/~scs/C-faq/s6 .html 了解更多详情

至于你传统分配的阵列,我不确定

是怎么回事。请记住,malloc允许您访问不同类型/区域内存
的内存,而不是传统分配的数组。



declare a and b like this

double *a[255];
double *b[255];
You have to declare a & b as pointers to an array of 255 doubles,
otherwise, how would the compiler know how much to "step over" when you
double dereference. I''m giving you a very simplistic answer (I think
you''re a newbie). Reading the c.l.c FAQ will help you better
understand the concepts. For now, you can start making use of your
program by just changing the declarations to match what I have above.

See: http://www.eskimo.com/~scs/C-faq/s6.html for more details
As for your conventionally allocated arrays, I am not sure what
happened. Remember, malloc gives you access to a different type/area
of memory than those conventionally allocated arrays would be place in.


这篇关于我的记忆力还不够吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆