dynamic memory allocation problem
I am working on a program that requires me to make use of 4 matrices sized [1000][1000].
I have created them using malloc()
, but when I try running the program 开发者_开发问答it just crashes and the memory usage shoots up to 2.5 GB. Please suggest any solution as soon as possible. I would be grateful..
4 matrices sized [1000][1000]
Why use malloc()
when you know at compile time how much memory you need? Dynamically allocating two-dimentional arrays is not the most trivial thing to do, neither is freeing them (see the C FAQ, Question 2.14 on one way to do this). Do not over-complicate your programs.
Why don't you run the program inside a debugger, such as gdb
, to see exactly where it crashes? It will help you narrow down the problem.
精彩评论