分配内存的问题 [英] Problems allocating memory

查看:50
本文介绍了分配内存的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我已经制作了一个类Matrix,它包含一个指向数据的指针和一些

方法,这些方法都返回修改后的矩阵副本某种程度上来说。

程序适用于小型矩阵,但随着矩阵维度的增加,它会在确定性位置崩溃,具体取决于数据,
机器和操作系统。

特别是当我用三个不同的机器/操作系统测试3000x3000矩阵

(占用超过30MB)时会发生这种情况。

崩溃发生在大量内存仍然可用时(例如,在
cygwin下,可用的虚拟内存超过1GB),我想不到

没有用于分配矩阵的连续空间。

我总是使用引用而从不指向矩阵,所以Matrix

对象不是动态分配的(数据,但是,由构造函数分配

)。这可能是堆栈/堆限制的问题吗?

有人可以帮我解释如何进一步调查

问题吗?


谢谢,

Ignazio

解决方案

" Neclepsio" <到******************* @ gmail.com写信息

新闻:45 ******** @ x- privat.org ...

:大家好。

:我做了一个类Matrix,其中包含指向数据的指针和

some

:所有方法都返回以某种方式修改的矩阵副本。



:程序适用于小型矩阵,但作为矩阵维度

:长大后它会在确定的位置崩溃,具体取决于数据,
:机器和操作系统。

:特别是当我用三个不同的机器/操作系统测试3000x3000矩阵

:(占用超过30MB)时会发生这种情况。



:当仍有大量内存可用时发生崩溃(例如,在
下:cygwin,可用虚拟内存超过1GB),我想不到

:有没有用于分配矩阵的连续空间。

:我总是使用引用而不是指向矩阵,所以Matrix
:对象不是动态分配的(但是,数据由构造函数分配

:)。这可能是堆栈/堆的问题

限制吗?

:有人可以帮我理解如何进一步调查

:问题?


要检查的第一件事是你提供了正确的析构函数,拷贝构造函数和
$的实现
实现b $ b复制赋值运算符。


但是为了让你的生活变得更轻松,你应该考虑使用std :: vector而不是a的
用于存储矩阵数据的原始指针。


hth -Ivan

-
http://ivan.vecerina.com/contact/?subject=NG_POST < - 电子邮件联系表单

Brainbench MVP for C ++< http://www.brainbench.com


感谢您的回复。


Ivan Vecerina写道:

首先要检查的是你提供了正确的析构函数,拷贝构造函数和

的实现。复制赋值运算符。



一切都好。第二个?


但是为了让你的生活更轻松,你应该考虑使用std :: vector代替原始的
用于存储矩阵数据的指针。



我需要原始指针来使用BLAS库。


谢谢,

Ignazio


Neclepsio写道:


大家好。

我做了一个类Matrix,它包含一个指向数据的指针和一些

方法,这些方法都返回以某种方式修改的矩阵的副本。

程序适用于小型矩阵,但随着矩阵维度的增加,它会在确定性位置崩溃,具体取决于数据,
机器和操作系统。

特别是当我用三个不同的机器/操作系统测试3000x3000矩阵

(占用超过30MB)时会发生这种情况。

崩溃发生在大量内存仍然可用时(例如,在
cygwin下,可用的虚拟内存超过1GB),我想不到

没有用于分配矩阵的连续空间。

我总是使用引用而从不指向矩阵,所以Matrix

对象不是动态分配的(数据,但是,由构造函数分配

)。这可能是堆栈/堆限制的问题吗?



它在三个不同平台下崩溃的事实表明没有。


有人可以帮助我关于如何进一步调查

问题的想法?



如果你可以在一个小程序中重现问题,那么在这里发布代码

。非常愿意看看。


>

谢谢,

Ignazio



john


Hi everyone.
I''ve made a class Matrix, which contains a pointer to the data and some
methods which all return a copy of the matrix modified in some way. The
program works quite well for small matrices, but as matrix dimension
grows up it crashes in deterministic locations depending on data,
machine and OS.
In particular, this happens when I test it with 3000x3000 matrices
(which take up more than 30MB) under three different machines/OSes. The
crash happens when much memory is still available (for example, under
cygwin, more than 1GB of virtual memory available), and I cannot think
there is no contiguous space for allocating the matrix.
I always use references and never pointers to matrices, so Matrix
objects are not dynamically allocated (the data, however, is allocated
by the constructor). Could this be a problem with stack/heap limitations?
Can someone help me with some idea on how to further investigate the
problem?

Thank you,
Ignazio

解决方案

"Neclepsio" <to*******************@gmail.comwrote in message
news:45********@x-privat.org...
: Hi everyone.
: I''ve made a class Matrix, which contains a pointer to the data and
some
: methods which all return a copy of the matrix modified in some way.
The
: program works quite well for small matrices, but as matrix dimension
: grows up it crashes in deterministic locations depending on data,
: machine and OS.
: In particular, this happens when I test it with 3000x3000 matrices
: (which take up more than 30MB) under three different machines/OSes.
The
: crash happens when much memory is still available (for example, under
: cygwin, more than 1GB of virtual memory available), and I cannot think
: there is no contiguous space for allocating the matrix.
: I always use references and never pointers to matrices, so Matrix
: objects are not dynamically allocated (the data, however, is allocated
: by the constructor). Could this be a problem with stack/heap
limitations?
: Can someone help me with some idea on how to further investigate the
: problem?

The first thing to check is that you have provided correct
implementations of the destructor, the copy-constructor, and the
copy-assignment operators.

But to make your life easier in the first place, you should consider
using std::vector instead of a raw pointer to store the matrix data.

hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com


Thank you for replying.

Ivan Vecerina wrote:

The first thing to check is that you have provided correct
implementations of the destructor, the copy-constructor, and the
copy-assignment operators.

Everything is ok. The second?

But to make your life easier in the first place, you should consider
using std::vector instead of a raw pointer to store the matrix data.

I needed raw pointers to use the BLAS library.

Thank you,
Ignazio


Neclepsio wrote:

Hi everyone.
I''ve made a class Matrix, which contains a pointer to the data and some
methods which all return a copy of the matrix modified in some way. The
program works quite well for small matrices, but as matrix dimension
grows up it crashes in deterministic locations depending on data,
machine and OS.
In particular, this happens when I test it with 3000x3000 matrices
(which take up more than 30MB) under three different machines/OSes. The
crash happens when much memory is still available (for example, under
cygwin, more than 1GB of virtual memory available), and I cannot think
there is no contiguous space for allocating the matrix.
I always use references and never pointers to matrices, so Matrix
objects are not dynamically allocated (the data, however, is allocated
by the constructor). Could this be a problem with stack/heap limitations?

The fact that it crashes under three different platforms suggests not.

Can someone help me with some idea on how to further investigate the
problem?

If you can reproduce the problem in a small program then post the code
here. Plently will be willing to take a look.

>
Thank you,
Ignazio

john


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

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