Why does declaring an int array of length INT_MAX create a segmentation fault? [duplicate]











up vote
0
down vote

favorite













This question already has an answer here:




  • Segmentation Fault, large arrays

    1 answer




The following code, when compiled and run, gives me a segmentation fault. Why is this?



#include <stdio.h>
#include <limits.h>

int main(void)
{
int fat_array[INT_MAX];

return 0;
}









share|improve this question













marked as duplicate by P.P. c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 22:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    Your system, that time, did not have enough memory for a local array that big. It tried and failed at run time.
    – chux
    Nov 10 at 22:22








  • 1




    stackoverflow without the .com
    – PSkocik
    Nov 10 at 22:22






  • 2




    You'd need 8 GiB of stack space for int fat_array[INT_MAX]; Unix-like systems are generous and normally give you 8 MiB of stack space; Windows is more conservative and normally only gives you 1 MiB. Either way, it's massively less space than needed. Either allocate the array at file scope (outside main()), or use dynamic memory allocation (malloc() et al).
    – Jonathan Leffler
    Nov 10 at 22:25

















up vote
0
down vote

favorite













This question already has an answer here:




  • Segmentation Fault, large arrays

    1 answer




The following code, when compiled and run, gives me a segmentation fault. Why is this?



#include <stdio.h>
#include <limits.h>

int main(void)
{
int fat_array[INT_MAX];

return 0;
}









share|improve this question













marked as duplicate by P.P. c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 22:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1




    Your system, that time, did not have enough memory for a local array that big. It tried and failed at run time.
    – chux
    Nov 10 at 22:22








  • 1




    stackoverflow without the .com
    – PSkocik
    Nov 10 at 22:22






  • 2




    You'd need 8 GiB of stack space for int fat_array[INT_MAX]; Unix-like systems are generous and normally give you 8 MiB of stack space; Windows is more conservative and normally only gives you 1 MiB. Either way, it's massively less space than needed. Either allocate the array at file scope (outside main()), or use dynamic memory allocation (malloc() et al).
    – Jonathan Leffler
    Nov 10 at 22:25















up vote
0
down vote

favorite









up vote
0
down vote

favorite












This question already has an answer here:




  • Segmentation Fault, large arrays

    1 answer




The following code, when compiled and run, gives me a segmentation fault. Why is this?



#include <stdio.h>
#include <limits.h>

int main(void)
{
int fat_array[INT_MAX];

return 0;
}









share|improve this question














This question already has an answer here:




  • Segmentation Fault, large arrays

    1 answer




The following code, when compiled and run, gives me a segmentation fault. Why is this?



#include <stdio.h>
#include <limits.h>

int main(void)
{
int fat_array[INT_MAX];

return 0;
}




This question already has an answer here:




  • Segmentation Fault, large arrays

    1 answer








c arrays segmentation-fault






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 22:20









Uclydde

7011419




7011419




marked as duplicate by P.P. c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 22:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by P.P. c
Users with the  c badge can single-handedly close c questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 10 at 22:33


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    Your system, that time, did not have enough memory for a local array that big. It tried and failed at run time.
    – chux
    Nov 10 at 22:22








  • 1




    stackoverflow without the .com
    – PSkocik
    Nov 10 at 22:22






  • 2




    You'd need 8 GiB of stack space for int fat_array[INT_MAX]; Unix-like systems are generous and normally give you 8 MiB of stack space; Windows is more conservative and normally only gives you 1 MiB. Either way, it's massively less space than needed. Either allocate the array at file scope (outside main()), or use dynamic memory allocation (malloc() et al).
    – Jonathan Leffler
    Nov 10 at 22:25
















  • 1




    Your system, that time, did not have enough memory for a local array that big. It tried and failed at run time.
    – chux
    Nov 10 at 22:22








  • 1




    stackoverflow without the .com
    – PSkocik
    Nov 10 at 22:22






  • 2




    You'd need 8 GiB of stack space for int fat_array[INT_MAX]; Unix-like systems are generous and normally give you 8 MiB of stack space; Windows is more conservative and normally only gives you 1 MiB. Either way, it's massively less space than needed. Either allocate the array at file scope (outside main()), or use dynamic memory allocation (malloc() et al).
    – Jonathan Leffler
    Nov 10 at 22:25










1




1




Your system, that time, did not have enough memory for a local array that big. It tried and failed at run time.
– chux
Nov 10 at 22:22






Your system, that time, did not have enough memory for a local array that big. It tried and failed at run time.
– chux
Nov 10 at 22:22






1




1




stackoverflow without the .com
– PSkocik
Nov 10 at 22:22




stackoverflow without the .com
– PSkocik
Nov 10 at 22:22




2




2




You'd need 8 GiB of stack space for int fat_array[INT_MAX]; Unix-like systems are generous and normally give you 8 MiB of stack space; Windows is more conservative and normally only gives you 1 MiB. Either way, it's massively less space than needed. Either allocate the array at file scope (outside main()), or use dynamic memory allocation (malloc() et al).
– Jonathan Leffler
Nov 10 at 22:25






You'd need 8 GiB of stack space for int fat_array[INT_MAX]; Unix-like systems are generous and normally give you 8 MiB of stack space; Windows is more conservative and normally only gives you 1 MiB. Either way, it's massively less space than needed. Either allocate the array at file scope (outside main()), or use dynamic memory allocation (malloc() et al).
– Jonathan Leffler
Nov 10 at 22:25














1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










What you are requesting is to have about 2,147,483,647integer spaces allocated to you. Each integer is usually four bytes so that's 8,589,934,588 bytes which is 8 gigabytes of memory. This is likely above the allowed amount of memory a single process is allowed to reserve, and for good reason, so you get an error.






share|improve this answer

















  • 2




    It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
    – P.P.
    Nov 10 at 22:45




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










What you are requesting is to have about 2,147,483,647integer spaces allocated to you. Each integer is usually four bytes so that's 8,589,934,588 bytes which is 8 gigabytes of memory. This is likely above the allowed amount of memory a single process is allowed to reserve, and for good reason, so you get an error.






share|improve this answer

















  • 2




    It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
    – P.P.
    Nov 10 at 22:45

















up vote
2
down vote



accepted










What you are requesting is to have about 2,147,483,647integer spaces allocated to you. Each integer is usually four bytes so that's 8,589,934,588 bytes which is 8 gigabytes of memory. This is likely above the allowed amount of memory a single process is allowed to reserve, and for good reason, so you get an error.






share|improve this answer

















  • 2




    It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
    – P.P.
    Nov 10 at 22:45















up vote
2
down vote



accepted







up vote
2
down vote



accepted






What you are requesting is to have about 2,147,483,647integer spaces allocated to you. Each integer is usually four bytes so that's 8,589,934,588 bytes which is 8 gigabytes of memory. This is likely above the allowed amount of memory a single process is allowed to reserve, and for good reason, so you get an error.






share|improve this answer












What you are requesting is to have about 2,147,483,647integer spaces allocated to you. Each integer is usually four bytes so that's 8,589,934,588 bytes which is 8 gigabytes of memory. This is likely above the allowed amount of memory a single process is allowed to reserve, and for good reason, so you get an error.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 10 at 22:26









Mitchel Paulin

1,504317




1,504317








  • 2




    It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
    – P.P.
    Nov 10 at 22:45
















  • 2




    It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
    – P.P.
    Nov 10 at 22:45










2




2




It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
– P.P.
Nov 10 at 22:45






It's slightly misleading to say "above the allowed amount of memory a single process is allowed to reserve". If it were to be heap allocted and the system has enough it's fine to use to reserve/allocate as much and there's no general limit for memory. The specific problem here is that it's "stack" allocated (aka automatic storage).
– P.P.
Nov 10 at 22:45





Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?