* Integer Array Size Problem
@ 2006-12-03 18:56 Digvijoy Chatterjee
[not found] ` <4DC346ED-14ED-4B5B-A957-083B070B3A5B@gmail.com>
2006-12-17 16:19 ` Tim Prince
0 siblings, 2 replies; 6+ messages in thread
From: Digvijoy Chatterjee @ 2006-12-03 18:56 UTC (permalink / raw)
To: gcc-help
Hi ,
I was trying to test algorithms with huge int arrays when i started
getting segfaults..here is a simple program which emulates this
behaviour...
Each time i run this program , it segfaults , This might be very naive
..but can anyone help me with what I am missing here ?
static const int N=10000000;
int main()
{
int c, i[N];
for (c=0;c<N ; c++ )
i[c]=c;
}
Thanks
Digz
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Integer Array Size Problem
[not found] ` <4DC346ED-14ED-4B5B-A957-083B070B3A5B@gmail.com>
@ 2006-12-03 19:18 ` Digvijoy Chatterjee
2006-12-03 21:13 ` Blake Huff
[not found] ` <e40293600612031307u1f8749b1m3c1d0a73a78e87e8@mail.gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Digvijoy Chatterjee @ 2006-12-03 19:18 UTC (permalink / raw)
To: Blake Huff; +Cc: gcc-help
Thanks,
the heap allocation code (malloc) ran without a problem..
so does a stack overflow mean ,that the stack can grow only to a
maximum size in the memory ??..who sets this ,and how does one change
this..
10,000,000 integers seems very little to overflow the stack.
-Digz
On 12/3/06, Blake Huff <stangmechanic@gmail.com> wrote:
> I believe this is what people refer to as stack overflow. Take a look at
> allocating the memory with something like malloc, i.e.,
>
> int *i = (int *) malloc(N * sizeof(int));
>
>
>
>
>
> Blake Huff
> stangmechanic@gmail.com
>
> "I'd like to take this opportunity to thank my cat for letting me live
> here."
>
>
> On Dec 3, 2006, at 12:56 PM, Digvijoy Chatterjee wrote:
>
> Hi ,
> I was trying to test algorithms with huge int arrays when i started
> getting segfaults..here is a simple program which emulates this
> behaviour...
> Each time i run this program , it segfaults , This might be very naive
> ..but can anyone help me with what I am missing here ?
>
> static const int N=10000000;
> int main()
> {
> int c, i[N];
> for (c=0;c<N ; c++ )
> i[c]=c;
> }
>
> Thanks
> Digz
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Integer Array Size Problem
2006-12-03 19:18 ` Digvijoy Chatterjee
@ 2006-12-03 21:13 ` Blake Huff
[not found] ` <e40293600612031307u1f8749b1m3c1d0a73a78e87e8@mail.gmail.com>
1 sibling, 0 replies; 6+ messages in thread
From: Blake Huff @ 2006-12-03 21:13 UTC (permalink / raw)
To: gcc-help
Digz:
Stack size is set by the OS, and there are typically ways to adjust
this in each OS. This is the part where we'll get berated for being
off topic, as this isn't a GCC question, but rather one appropriate
for a general programming list, or for one about your OS.
The default stack size for some OS's (like Mac OS X) is 8 megabytes.
Ten million integers at 4 bytes each would take 40 million bytes ~ 40
megabytes, and overflow the stack.
If you're interested in learning more, I suggest doing Google
searches for stack size/allocation, etc.. However, I think the
preferred technique is to malloc large arrays, in the event that your
code is moved from a machine/OS with a large stack to a machine with
an unacceptably small stack, etc.
Blake
"When the going gets tough, the tough get aeronautical."-Howling Mad
Murdoch
On Dec 3, 2006, at 1:18 PM, Digvijoy Chatterjee wrote:
> Thanks,
> the heap allocation code (malloc) ran without a problem..
> so does a stack overflow mean ,that the stack can grow only to a
> maximum size in the memory ??..who sets this ,and how does one change
> this..
> 10,000,000 integers seems very little to overflow the stack.
>
> -Digz
>
> On 12/3/06, Blake Huff <stangmechanic@gmail.com> wrote:
>> I believe this is what people refer to as stack overflow. Take a
>> look at
>> allocating the memory with something like malloc, i.e.,
>>
>> int *i = (int *) malloc(N * sizeof(int));
>>
>>
>>
>>
>>
>> Blake Huff
>> stangmechanic@gmail.com
>>
>> "I'd like to take this opportunity to thank my cat for letting me
>> live
>> here."
>>
>>
>> On Dec 3, 2006, at 12:56 PM, Digvijoy Chatterjee wrote:
>>
>> Hi ,
>> I was trying to test algorithms with huge int arrays when i started
>> getting segfaults..here is a simple program which emulates this
>> behaviour...
>> Each time i run this program , it segfaults , This might be very
>> naive
>> ..but can anyone help me with what I am missing here ?
>>
>> static const int N=10000000;
>> int main()
>> {
>> int c, i[N];
>> for (c=0;c<N ; c++ )
>> i[c]=c;
>> }
>>
>> Thanks
>> Digz
>>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Fwd: Integer Array Size Problem
[not found] ` <e40293600612031307u1f8749b1m3c1d0a73a78e87e8@mail.gmail.com>
@ 2006-12-03 21:16 ` Dima Sorkin
2006-12-04 2:41 ` Tim Prince
0 siblings, 1 reply; 6+ messages in thread
From: Dima Sorkin @ 2006-12-03 21:16 UTC (permalink / raw)
To: gcc-help
On 12/3/06, Digvijoy Chatterjee wrote:
> Thanks,
> the heap allocation code (malloc) ran without a problem..
> so does a stack overflow mean ,that the stack can grow only to a
> maximum size in the memory ??..who sets this ,and how does one change
> this..
ulimit
> 10,000,000 integers seems very little to overflow the stack.
It is a least 40MB which seems unreasonably high. See below on my
machine (in kB):
bash-3.00$ ulimit -s
10240
Regards,
Dima.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Fwd: Integer Array Size Problem
2006-12-03 21:16 ` Fwd: " Dima Sorkin
@ 2006-12-04 2:41 ` Tim Prince
0 siblings, 0 replies; 6+ messages in thread
From: Tim Prince @ 2006-12-04 2:41 UTC (permalink / raw)
To: Dima Sorkin; +Cc: gcc-help
Dima Sorkin wrote:
> On 12/3/06, Digvijoy Chatterjee wrote:
>> Thanks,
>> the heap allocation code (malloc) ran without a problem..
>> so does a stack overflow mean ,that the stack can grow only to a
>> maximum size in the memory ??..who sets this ,and how does one change
>> this..
> ulimit
>
>> 10,000,000 integers seems very little to overflow the stack.
> It is a least 40MB which seems unreasonably high. See below on my
> machine (in kB):
>
> bash-3.00$ ulimit -s
> 10240
On my current (32-bit Windows) platform:
$ ulimit -s
2032
So, if you intend portable code, you surely can't count on availability
of larger stacks. 1MB per thread used to be a typical hard limit for
static linked 32-bit linux libraries. The 1MB per thread stack thing
was ubiquitous enough to require hardware level changes since the
original P4, which had cache mapping conflicts ("64k aliasing") between
stacks at 1MB intervals, as implemented by the most popular C platform.
The hardware fix still is vulnerable to problems with stacks at
intervals of multiples of 8MB, if I understand the situation correctly.
Standard C, of course, says nothing about stacks and their sizes, but it
doesn't say that you can ignore limitations of common platforms.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Integer Array Size Problem
2006-12-03 18:56 Integer Array Size Problem Digvijoy Chatterjee
[not found] ` <4DC346ED-14ED-4B5B-A957-083B070B3A5B@gmail.com>
@ 2006-12-17 16:19 ` Tim Prince
1 sibling, 0 replies; 6+ messages in thread
From: Tim Prince @ 2006-12-17 16:19 UTC (permalink / raw)
To: Digvijoy Chatterjee; +Cc: gcc-help
Digvijoy Chatterjee wrote:
> Hi ,
> I was trying to test algorithms with huge int arrays when i started
> getting segfaults..here is a simple program which emulates this
> behaviour...
> Each time i run this program , it segfaults , This might be very naive
> ..but can anyone help me with what I am missing here ?
>
> static const int N=10000000;
> int main()
> {
> int c, i[N];
> for (c=0;c<N ; c++ )
> i[c]=c;
> }
>
Evidently, this depends on platform (e.g. 32- or 64-bit), possibly on
compiler options (e.g. mc-model) or shell settings (e.g. ulimit), none
of which you have divulged. Not giving such information doesn't make it
On Topic.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-12-17 16:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-12-03 18:56 Integer Array Size Problem Digvijoy Chatterjee
[not found] ` <4DC346ED-14ED-4B5B-A957-083B070B3A5B@gmail.com>
2006-12-03 19:18 ` Digvijoy Chatterjee
2006-12-03 21:13 ` Blake Huff
[not found] ` <e40293600612031307u1f8749b1m3c1d0a73a78e87e8@mail.gmail.com>
2006-12-03 21:16 ` Fwd: " Dima Sorkin
2006-12-04 2:41 ` Tim Prince
2006-12-17 16:19 ` Tim Prince
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).