Skip to contentSkip to conversation

Memory Allocation Problem

DISCUSSION Ankit Jain 4 participants 4 messages Sep 15, 2004

lore
Share & tools
lore

Ankit Jain

author
#0 lore raw
      1 #include <stdio.h>
      2 int main()
      3 {
      4    double a[1450][1450];
      5
      6    a[1449][0] = 999;
      7    printf( "%lf\n", a[1449][0] );
      8    return 1;
      9 }

it gives segementation fault

if i use malloc also it gives wrong result

what to do?

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html

#1 lore raw

1450 * 1450 * 8 = 16 MEGA!!!!!!!!!
So, you need a 16 mega of stack which I think is a little too much ;)

The solution is to malloc() but check if you have 16 mega of ram ;)

Quoted 22 lines · Ankit Jain
      1 #include <stdio.h>
      2 int main()
      3 {
      4    double a[1450][1450];
      5
      6    a[1449][0] = 999;
      7    printf( "%lf\n", a[1449][0] );
      8    return 1;
      9 }

it gives segementation fault

if i use malloc also it gives wrong result

what to do?

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping" your friends today! Download Messenger Now http://uk.messenger.yahoo.com/download/index.html

#2 lore raw

Or workaround could be you make declaration of 'a' global.

-----Original Message-----
From: [email protected] [mailto:[email protected]]On Behalf Of Suciu Flavius
Sent: Wednesday, September 15, 2004 9:06 PM
To: [email protected]
Cc: [email protected]
Subject: Re: Memory Allocation Problem

1450 * 1450 * 8 = 16 MEGA!!!!!!!!!
So, you need a 16 mega of stack which I think is a little too much ;)

The solution is to malloc() but check if you have 16 mega of ram ;)

Quoted 15 lines · Ankit Jain
      1 #include <stdio.h>
      2 int main()
      3 {
      4    double a[1450][1450];
      5
      6    a[1449][0] = 999;
      7    printf( "%lf\n", a[1449][0] );
      8    return 1;
      9 }

it gives segementation fault

if i use malloc also it gives wrong result

Quoted 9 lines

what to do?

ankit

________________________________________________________________________
Yahoo! Messenger - Communicate instantly..."Ping"
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at [email protected] and delete this mail.
_____________________________________________________________________

#3 lore raw
In reply to Ankit Jain

Hi Ankit,

Your OS probably does not provide that many megabytes of STACK space.

Allocate your enormous 2-dimensional array on the HEAP or in the BSS or in the DATA areas instead.

Or check out if your can adjust the size of your STACK to around 32 MB. That might be a linker option. Depends on your OS.

HTH,
--Eljay