memory allocation of stacks and heaps

Hi,
1) How are the size of stacks and heaps allocated?
a) Are these sizes controlled by the operating system or by the compiler?
b) Can the programmer control these sizes?
2) Are the stacks and heaps used by different programs grouped together in something like a stack/heap area Or are they allocated randomly?

==================================
top of memory
==================================
---(start of stack area)---
...stack allocated for pgm1
...stack allocated for pgm2
(nxt available stack)
(available stack)
(available stack)
.
.
.
...(available stack)
---(end of stack area---
---(start of heap area---
...heap allocated for pgm1
...heap allocated for pgm2
...(nxt available heap)
...(available heap)
...(available heap)
.
.
.
...(available heap)
---(end of heap area)
==================================+


==================================+
bottom of memory


OR


top of memory
==================================+
---(start of stack/heap area)
stack allocated for pgm1
heap allocated for pgm1
----
stack allocated for pgm2
heap allocated for pgm2
----
(nxt available stack)
(nxt available heap)
----
(available stack)
(available heap)
.
.
.
---(end of stack/heap area)
==================================+
. |
. |
. |
==================================+
bottom of memory


Thanks.
1) By the operating system.
1a) By the operating system.
1b) It depends on the platform/OS.
2) They are allocated however the OS feels like it.
Thanks!
Topic archived. No new replies allowed.