Unix Programming - Heap vs Stack

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > July 2007 > Heap vs Stack





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Heap vs Stack
Nehil

2007-07-08, 7:22 am

I would like to know which is dynamic in nature.
if i refer the C memory model (Richard Steven), it is shown that both
stack and heap grow towards each other.
Now, can one go into other's area and hence effecting the size of
other memory area.

Does any limit exist upto which a stack or a heap can grow. and if it
is there then who decides the limit?

plz clarify.

David T. Ashley

2007-07-08, 1:21 pm

"Nehil" <nehilparashar@gmail.com> wrote in message
news:1183894832.890803.254790@r34g2000hsd.googlegroups.com...
>I would like to know which is dynamic in nature.
> if i refer the C memory model (Richard Steven), it is shown that both
> stack and heap grow towards each other.
> Now, can one go into other's area and hence effecting the size of
> other memory area.
>
> Does any limit exist upto which a stack or a heap can grow. and if it
> is there then who decides the limit?


Stack and heap are in some sense related concepts, except for the required
order of release. It is not uncommon with certain development tools to have
functions that will claim space on the stack and return a pointer (similar
to malloc). However, such claimed areas have to be released from the bottom
up (they can't be preserved when a function returns).

In a modern operating system (on modern hardware), the limit is typically a
feature of the operating system on the platform. 4GB is typical. It
doesn't normally make sense to have this limit configurable -- with modern
hardware (pages, page faults, and all that) the system can normally move
stuff around as the program's memory needs grow until the limit is reached.
--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)


Scott Lurndal

2007-07-09, 1:26 pm

Nehil <nehilparashar@gmail.com> writes:
>I would like to know which is dynamic in nature.
>if i refer the C memory model (Richard Steven), it is shown that both
>stack and heap grow towards each other.
>Now, can one go into other's area and hence effecting the size of
>other memory area.
>
>Does any limit exist upto which a stack or a heap can grow. and if it
>is there then who decides the limit?
>
>plz clarify.
>

$ ulimit -aS
address space limit (kbytes) (-M) unlimited
core file size (blocks) (-c) 0
cpu time (seconds) (-t) unlimited
data size (kbytes) (-d) unlimited
file size (blocks) (-f) unlimited
locks (-L) unlimited
locked address space (kbytes) (-l) 32
nofile (-n) 1024
nproc (-u) 16383
pipe buffer size (bytes) (-p) 4096
resident set size (kbytes) (-m) unlimited
socket buffer size (bytes) (-b) 4096
stack size (kbytes) (-s) 10240
threads (-T) not supported
process size (kbytes) (-v) unlimited

'stack size' defines the maximum amount of space that can
be used by the stack. 'data size' bounds the heap. These
are per-process limits.

see man setrlimit, pam_limits, man ulimit, et. al.

scott
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com