public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Memory Allocation Problem
@ 2004-09-15  6:02 Ankit Jain
  2004-09-15  6:15 ` Sriharsha Vedurmudi
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Ankit Jain @ 2004-09-15  6:02 UTC (permalink / raw)
  To: gcc, linux prg

      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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Memory Allocation Problem
  2004-09-15  6:02 Memory Allocation Problem Ankit Jain
@ 2004-09-15  6:15 ` Sriharsha Vedurmudi
  2004-09-15  6:34   ` Ankit Jain
  2004-09-15  7:31 ` Suciu Flavius
  2004-09-15 12:02 ` Eljay Love-Jensen
  2 siblings, 1 reply; 8+ messages in thread
From: Sriharsha Vedurmudi @ 2004-09-15  6:15 UTC (permalink / raw)
  To: Ankit Jain; +Cc: gcc


Ankit Jain wrote:

>      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
>  
>
I tried, but it ran well. Except ofcourse, I changed "return 1" to 
"return 0" (you dont want to return an error from Main)

>if i use malloc also it gives wrong result
>
>what to do?
>  
>
I guess your system is lacking the memory required to allocate 1450 * 
1450 * 4 bytes on stack. Try making it static.

-Harsha.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Memory Allocation Problem
  2004-09-15  6:15 ` Sriharsha Vedurmudi
@ 2004-09-15  6:34   ` Ankit Jain
  0 siblings, 0 replies; 8+ messages in thread
From: Ankit Jain @ 2004-09-15  6:34 UTC (permalink / raw)
  To: Sriharsha Vedurmudi, gcc, linux prg

 --- Sriharsha Vedurmudi
<sriharsha.v@redpinesignals.com> wrote: 
> 
> Ankit Jain wrote:
> 
> >      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 }
> >

well i am sorry its return 0 only

i have 128 mb RAM. it gives segmentation fault while
running

i tried it on 512 MB Ram also it gives segemntation
fault. around 400 MB of Ram was free when i tried to
run that program

thanks 
ankit
> >
> >it gives segementation fault
> >  
> >
> I tried, but it ran well. Except ofcourse, I changed
> "return 1" to 
> "return 0" (you dont want to return an error from
> Main)
> 
> >if i use malloc also it gives wrong result
> >
> >what to do?
> >  
> >
> I guess your system is lacking the memory required
> to allocate 1450 * 
> 1450 * 4 bytes on stack. Try making it static.
> 
> -Harsha.
> 
> >ankit
> >
>
>________________________________________________________________________
> >Yahoo! Messenger - Communicate instantly..."Ping" 
> >your friends today! Download Messenger Now 
> >http://uk.messenger.yahoo.com/download/index.html
> >  
> >
>  

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: Memory Allocation Problem
  2004-09-15  7:31 ` Suciu Flavius
@ 2004-09-15  6:38   ` Chandan Chopra
  0 siblings, 0 replies; 8+ messages in thread
From: Chandan Chopra @ 2004-09-15  6:38 UTC (permalink / raw)
  To: 'Suciu Flavius', linux-c-programming; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 2137 bytes --]


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

-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org]On Behalf Of Suciu
Flavius
Sent: Wednesday, September 15, 2004 9:06 PM
To: linux-c-programming@vger.kernel.org
Cc: gcc-help@gcc.gnu.org
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 ;)


Ankit Jain wrote:
>       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
>

-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
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 netadmin@patni.com and delete this mail. 
_____________________________________________________________________

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Memory Allocation Problem
  2004-09-15  6:02 Memory Allocation Problem Ankit Jain
  2004-09-15  6:15 ` Sriharsha Vedurmudi
@ 2004-09-15  7:31 ` Suciu Flavius
  2004-09-15  6:38   ` Chandan Chopra
  2004-09-15 12:02 ` Eljay Love-Jensen
  2 siblings, 1 reply; 8+ messages in thread
From: Suciu Flavius @ 2004-09-15  7:31 UTC (permalink / raw)
  To: gcc-help; +Cc: linux-c-programming

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 ;)


Ankit Jain wrote:
>       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
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Memory Allocation Problem
  2004-09-15  6:02 Memory Allocation Problem Ankit Jain
  2004-09-15  6:15 ` Sriharsha Vedurmudi
  2004-09-15  7:31 ` Suciu Flavius
@ 2004-09-15 12:02 ` Eljay Love-Jensen
  2004-09-15 12:07   ` Sriharsha Vedurmudi
  2 siblings, 1 reply; 8+ messages in thread
From: Eljay Love-Jensen @ 2004-09-15 12:02 UTC (permalink / raw)
  To: Ankit Jain, gcc, linux prg

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Memory Allocation Problem
  2004-09-15 12:02 ` Eljay Love-Jensen
@ 2004-09-15 12:07   ` Sriharsha Vedurmudi
  2004-09-15 12:18     ` Eljay Love-Jensen
  0 siblings, 1 reply; 8+ messages in thread
From: Sriharsha Vedurmudi @ 2004-09-15 12:07 UTC (permalink / raw)
  To: gcc

Hi Eljay,

  I've just discovered that the problem is not with the declaration 
(compiling and running the program in Linux RH8 with gcc 3.2).

I have run the program in a Terminal Window under Gnome GUI and a 
Non-GUI environment (basically Ctrl+Alt+F2 and F7).
The program works well under GUI terminal, but fails with a seg 
violation in non-gui environment).

 Further I traced that the program was working past the assignment 
statement "a[1449][0] = 999.343" (or something similar). It was sev 
faulting when Im trying to pass this value to a function (printf or any 
other user-defined function). Thats what I dont understand....

_Harsha_

Eljay Love-Jensen wrote:

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Memory Allocation Problem
  2004-09-15 12:07   ` Sriharsha Vedurmudi
@ 2004-09-15 12:18     ` Eljay Love-Jensen
  0 siblings, 0 replies; 8+ messages in thread
From: Eljay Love-Jensen @ 2004-09-15 12:18 UTC (permalink / raw)
  To: Sriharsha Vedurmudi, gcc

Hi Sriharsha,

 >It was sev faulting when Im trying to pass this value to a function 
(printf or any other user-defined function). Thats what I dont understand....

That's usually an indicator that the available STACK is being exceeding.

(It was only a couple decades ago that I had to work with a 256 byte 
stack.  Times changes.)

--Eljay

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-09-15 12:18 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-15  6:02 Memory Allocation Problem Ankit Jain
2004-09-15  6:15 ` Sriharsha Vedurmudi
2004-09-15  6:34   ` Ankit Jain
2004-09-15  7:31 ` Suciu Flavius
2004-09-15  6:38   ` Chandan Chopra
2004-09-15 12:02 ` Eljay Love-Jensen
2004-09-15 12:07   ` Sriharsha Vedurmudi
2004-09-15 12:18     ` Eljay Love-Jensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).