You are not logged in. Please login at www.codechef.com to post your questions!

×

Memory Fragmentation

why codechef compiler is unable to provide contiguous memory location to the array of size greater than 10^6 in local scope statically whereas it is possible dynamically.

asked 28 Jun '16, 11:47

demo01's gravatar image

2★demo01
7012
accept rate: 12%


Yes, you cannot locally declare an array of size 10^6 in gcc compiler because when you declare an array in a function it gets allocated in stack memory and this memory has less space as compared to heap memory.

Instead of direct declaration use malloc function for the declaration(Array will be allocated in heap memory).

It does not matter whether you declare the array of such size statically or dynamically, in both the cases yo will get the run time error.

link

answered 28 Jun '16, 12:51

mayur_kharche's gravatar image

4★mayur_kharche
382
accept rate: 100%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×20
×8
×5

question asked: 28 Jun '16, 11:47

question was seen: 382 times

last updated: 28 Jun '16, 12:51