Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-07-2004, 12:55 AM   #1
LQ Newbie
Registered: Sep 2004
Posts: 28

Rep: Reputation: 15
Stack size decision

hii group..
i m having a query abt how the stack size is decided...
V know that For a particualr programm v have 4 different or segments in memory...
1)Code segment
2)Data segment
3)Heap segment
4)Stack segment..

Now when v talk abt virtual memeory scenario its also known that 3 GB of memory is allocated by OS for these sections in all...

Starting or 0th byte given to the code segment n then proceeding upwards ..also the stack grows downwards frm the location 3rd GBth location.This whole is decided by OS...,ie.,Os decides the size of the complete memory allocated to these segments in all...

My questions r->

1).According to linux implementation v had 4 GB of Virtual Memory so "y it starts the stack with 3GB memory" ,ie,....Y it alloactes 3GB memory all these segments in all....Y cant 4GB full is allocated...

2)Also if i assume that i had no underlying OS n still i had to prform the task of alloacting space to all these segments then how i decide how much space is allocated to them in all..

3)Also How Stack ptr will b initialised?

4) In normal scenario how this stack ptr gets initialised...
Old 10-07-2004, 10:06 AM   #2
jim mcnamara
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Maybe I'm missing something - but:

The kernel has a kernel mode stack, each program has a separate user mode stack.

When a program is compiled the initial size of the program segments in memory
are determined at this point. When you activate the image (run your program) the
OS calls sbrk() to allocate the space your program says it needs, including the
stack pointer and stack space. If the request is for a huge hunk of memory, the
OS allocates virtual storage in the pagefile.

In practice, you don't have 3GB of memory to play with, unless one of two things
is true:

Physical memory is that large
Pagefile is large enough to accomodate it (plus what other processes consume)

Finally, compilers can and often do set limits on user stack space.

So, really what do you want to know? You usually do not have 3GB to play with
in memory, and if you actually do have pagefile space, performance will likely
be awful. The kernel keeps 1GB for itself. Address space is 4GB, so processes
get a theorectical 3GB of user space. When your process is the current process,
kernel memory is part of your process, but it cannot be accessed by user mode
Old 10-08-2004, 04:32 AM   #3
LQ Newbie
Registered: Sep 2004
Posts: 28

Original Poster
Rep: Reputation: 15
hii buddy u r saying that

"You usually do not have 3GB to play with
in memory, and if you actually do have pagefile space, performance will likely
be awful. "

But i can send u a link in which the person has mentioned abt the 3GB n 1GB partitions of the virtual memory.....
u can check this out here...

U can download the slide show n view it...

But my main question is "if i dont got any OS sitting with me n doing or managing the stuff for space decision of all segments then ---
1)How CAN I DECIDE the whole segment space
2) How the Stack pointer will get initialised
3) And how the stack pointer gets initialised in normal scenario...

Last edited by atul_mehrotra; 10-08-2004 at 04:46 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
FC4 - new stack size? DJOtaku Fedora 2 10-07-2005 12:22 PM
How do you increase a kernel stack size? ginda Linux - Newbie 4 01-24-2005 06:52 PM
Stack Size Decision atul_mehrotra Linux - General 0 10-07-2004 01:01 AM
Kernel Stack Size option Corallis Linux - Newbie 2 09-07-2004 09:50 PM
C++ programs initial stack size. uncle_kevin Programming 1 07-05-2004 01:35 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:59 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration