wantobegeek
wantobegeek

Reputation: 1725

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..

Upvotes: 1

Views: 455

Answers (2)

RWS
RWS

Reputation: 616

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.

Upvotes: 1

RarrRarrRarr
RarrRarrRarr

Reputation: 3910

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.

Upvotes: 0

Related Questions