这是记忆问题吗? [英] Is this a memory problem?

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

问题描述

大家好,

我用Kdevelop在Linux上构建一些科学模拟。如果我设置

数组的大小N = 8000,程序运行正常。但是,如果我将
设置为数组N大于10000(实际上,我需要的是
是80000),程序会出现分段错误。如果我将

N设置为不同的值,那么报告分段错误的位置是不同的。


什么问题通常是这个吗?我想一定是一些内存错误。我使用

Valgrind检查内存,在有分段错误的行,它

报告不在地址0xxxxxxxx的映射区域内访问。


任何人都知道解决方案吗?我怎么处理这个问题?谢谢。


-Steve

folks,

I use Kdevelop to build some scientific simulation on Linux. If I set
the size of an array N = 8000, the program works fine. However, if I
set the array N some number greater than 10000 (actually, what I need
is 80000), the program has segmentation error. The intersting thing is
that the positions reporting segmentation error are different if I set
N to be different values.

What problem is this usually? I guess must be some memory error. I use
Valgrind to check the memory, at the line with segmentation error, it
reports "Access not within mapped region at address 0xxxxxxxx".

Anyone know the solution? How cound I handle this problem? Thanks.

-Steve

推荐答案

* syang8:
* syang8:

>

我使用Kdevelop在Linux上构建一些科学模拟。如果我设置

数组的大小N = 8000,程序运行正常。但是,如果我将
设置为数组N大于10000(实际上,我需要的是
是80000),程序会出现分段错误。如果我将

N设置为不同的值,那么报告分段错误的位置是不同的。


什么问题通常是这个吗?我想一定是一些内存错误。我使用

Valgrind检查内存,在有分段错误的行,它

报告不在地址0xxxxxxxx的映射区域内访问。


任何人都知道解决方案吗?我怎么处理这个问题?谢谢。
>
I use Kdevelop to build some scientific simulation on Linux. If I set
the size of an array N = 8000, the program works fine. However, if I
set the array N some number greater than 10000 (actually, what I need
is 80000), the program has segmentation error. The intersting thing is
that the positions reporting segmentation error are different if I set
N to be different values.

What problem is this usually? I guess must be some memory error. I use
Valgrind to check the memory, at the line with segmentation error, it
reports "Access not within mapped region at address 0xxxxxxxx".

Anyone know the solution? How cound I handle this problem? Thanks.



听起来你要将数组声明为局部变量,它使用堆栈空间来获取
。在命名空间范围内声明它,或动态分配它。
。动态分配数组的一种简单,安全的方法是使用std :: vector



-

A:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的是什么?

It sounds like you''re declaring the array as a local variable, where it
uses stack space. Declare it at namespace scope, or allocate it
dynamically. A simple, safe way to allocate an array dynamically is to
use std::vector.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?




Alf P. Steinbach写道:

Alf P. Steinbach wrote:

* syang8:
* syang8:


我使用Kdevelop在Linux上构建一些科学模拟。如果我设置

数组的大小N = 8000,程序运行正常。但是,如果我将
设置为数组N大于10000(实际上,我需要的是
是80000),程序会出现分段错误。如果我将

N设置为不同的值,那么报告分段错误的位置是不同的。


什么问题通常是这个吗?我想一定是一些内存错误。我使用

Valgrind检查内存,在有分段错误的行,它

报告不在地址0xxxxxxxx的映射区域内访问。


任何人都知道解决方案吗?我怎么处理这个问题?谢谢。

I use Kdevelop to build some scientific simulation on Linux. If I set
the size of an array N = 8000, the program works fine. However, if I
set the array N some number greater than 10000 (actually, what I need
is 80000), the program has segmentation error. The intersting thing is
that the positions reporting segmentation error are different if I set
N to be different values.

What problem is this usually? I guess must be some memory error. I use
Valgrind to check the memory, at the line with segmentation error, it
reports "Access not within mapped region at address 0xxxxxxxx".

Anyone know the solution? How cound I handle this problem? Thanks.



听起来你要将数组声明为一个局部变量,它使用堆栈空间来获取
。在命名空间范围内声明它,或动态分配它。
。一种动态分配数组的简单,安全的方法是使用std :: vector


It sounds like you''re declaring the array as a local variable, where it
uses stack space. Declare it at namespace scope, or allocate it
dynamically. A simple, safe way to allocate an array dynamically is to
use std::vector.



不是堆栈用于功能调用?局部变量应该在
堆中,对吗?我只掌握基本的C / C ++编程知识。到目前为止,我还没有获得有关命名空间的高级知识。在名称空间中定义的变量

存储在哪里?我所知道的动态分配数组

就是使用new和删除。我想知道你是否可以向我推荐

任何好的参考书(书籍或在线资源)。谢谢。

Isn''t the stack used in function calls? The local variable should be in
heap, right? I only have knowledge in basic C/C++ programming. I don''t
have advanced knowledge on namespace so far. Where aer the variables
defined in a namespace stored? Also what I know to allocate array
dynamically is to use "new" and "delete". I wonder if you can recommend
any good reference (books or online resources) to me. Thanks.


* syang8:
* syang8:

Alf P. Steinbach写道:
Alf P. Steinbach wrote:

> * syang8:
>* syang8:

>>我使用Kdevelop在Linux上构建一些科学模拟。如果我设置数组N = 8000的大小,程序运行正常。但是,如果我将数组N设置为大于10000的数字(实际上,我需要的是80000),程序会出现分段错误。有趣的是,如果我将N设置为不同的值,报告分段错误的位置是不同的。

这通常是什么问题?我想一定是一些内存错误。我使用
Valgrind检查内存,在有分段错误的行上,它报告不在地址0xxxxxxxx的映射区域内访问。

任何人都知道解决方案?我怎么处理这个问题?谢谢。
>>I use Kdevelop to build some scientific simulation on Linux. If I set
the size of an array N = 8000, the program works fine. However, if I
set the array N some number greater than 10000 (actually, what I need
is 80000), the program has segmentation error. The intersting thing is
that the positions reporting segmentation error are different if I set
N to be different values.

What problem is this usually? I guess must be some memory error. I use
Valgrind to check the memory, at the line with segmentation error, it
reports "Access not within mapped region at address 0xxxxxxxx".

Anyone know the solution? How cound I handle this problem? Thanks.


听起来你将数组声明为局部变量,它使用堆栈空间。在命名空间范围内声明它,或动态分配它。动态分配数组的一种简单,安全的方法是使用std :: vector。

It sounds like you''re declaring the array as a local variable, where it
uses stack space. Declare it at namespace scope, or allocate it
dynamically. A simple, safe way to allocate an array dynamically is to
use std::vector.



不是函数调用中使用的堆栈吗?


Isn''t the stack used in function calls?



是的,虽然这不在语言定义之内(它是一个

实现细节)。

Yes, although that''s outside the language definition (it''s an
implementation detail).


本地变量应该在堆中,对吗?
The local variable should be in heap, right?



不确定你的意思。

Not sure what you mean.


我只懂基本的C / C ++编程。到目前为止,我还没有获得有关命名空间的高级知识。在名称空间中定义的变量

存储在哪里?
I only have knowledge in basic C/C++ programming. I don''t
have advanced knowledge on namespace so far. Where aer the variables
defined in a namespace stored?



编译器知道在命名空间声明的所有变量的总大小

范围(在任何函数或类之外),并且分配了这个内存当

程序加载时。

The compiler knows the total size of all variables declared at namespace
scope (outside any function or class), and this memory is allocated when
the program is loaded.


另外我知道分配数组

动态是使用新和删除。
Also what I know to allocate array
dynamically is to use "new" and "delete".



使用std :: vector,比如


#include< vector>


...


std :: vector< MyClassmyArray(80000);


因为你动态分配你可以将此作为本地

变量;它只在本地使用一小部分固定的内存。

Use a std::vector, like

#include <vector>

...

std::vector<MyClassmyArray( 80000 );

Since you''re allocating dynamically you can have this as a local
variable; it only uses a small fixed amount of memory locally.


我想知道你是否可以推荐

任何好的参考书(书籍)或者在线资源)给我。谢谢。
I wonder if you can recommend
any good reference (books or online resources) to me. Thanks.



加速C ++。


-

答:因为它弄乱了订单人们通常会阅读文字。

问:为什么这么糟糕?

A:热门帖子。

问:什么是usenet和电子邮件中最烦人的事情是什么?

Accelerated C++.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


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

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