Click here to Skip to main content
15,903,175 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Window on Dialog Pin
_AnsHUMAN_ 4-Jun-06 23:31
_AnsHUMAN_ 4-Jun-06 23:31 
QuestionRe: Window on Dialog Pin
Manjunath S4-Jun-06 23:47
Manjunath S4-Jun-06 23:47 
Questionabout edit box Pin
yogendra kaushik4-Jun-06 22:55
yogendra kaushik4-Jun-06 22:55 
AnswerRe: about edit box Pin
_AnsHUMAN_ 4-Jun-06 22:59
_AnsHUMAN_ 4-Jun-06 22:59 
AnswerRe: about edit box Pin
Hamid_RT4-Jun-06 23:05
Hamid_RT4-Jun-06 23:05 
AnswerRe: about edit box Pin
ThatsAlok5-Jun-06 0:26
ThatsAlok5-Jun-06 0:26 
Questionconfused about system stack Pin
George_George4-Jun-06 22:54
George_George4-Jun-06 22:54 
AnswerRe: confused about system stack Pin
Viorel.5-Jun-06 0:19
Viorel.5-Jun-06 0:19 
My viewpoint is the following:

When you start a C++ program, it consists of four parts: the code segment, the data segment; a unique heap area; a unique stack area.

The code segment contains microprocessor instructions obtained after successful compilation.

The data segment contains at least data declared with "static" modifier, as well as quoted strings.

When you call a function, for instance "f(1,2,3)", then the arguments 1, 2 and 3 are pushed on the stack (the particular order depends on some factors). Also a return address (the address of the next instruction, after your "f(1,2,3)") is pushed on the stack. Within the function, when you access an argument, you actually access a value from the stack. When the function finishes and returns back to the pushed address, the pushed values are popped from the stack and are lost, and the stack returns to its previous state.

Push and pop operations are performed by microprocessor using special pointer, stored in a register, which points to the top of the stack.

If you call a function again, the same stack is re-used.

If you have some local variables in your function, they are allocated on the same stack, somewhere above the pushed parameters and return address. That’s why you can crash your program if you access local variables incorrectly. For instance, by accessing a local array using invalid index.

Local variables declared with "static" modifier are allocated in data segment instead of the stack. This way, the value of static local variables is preserved between function calls.

If you call functions recursively, or use too large local variables, the stack becomes full.

When you use new operator or malloc function, data are allocated from the heap area. In contrast with the stack area, which are automatically cleared back when you return from a function, the heap-allocated data must be release explicitly, using delete or free.

If you allocate too much data or forget to release unneeded ones, the heap area becomes full. If you uses invalid pointers, you can corrupt the heap area.

So, there is a single stack and a single heap shared by your functions, and each program has its own stack and heap.

Windows applications also can allocate data in a specific manner using system functions like GlobalAlloc and others.

That is my vision on stack and heap.
GeneralRe: confused about system stack [modified] Pin
George_George5-Jun-06 1:38
George_George5-Jun-06 1:38 
GeneralRe: confused about system stack [modified] Pin
Viorel.5-Jun-06 2:05
Viorel.5-Jun-06 2:05 
GeneralRe: confused about system stack [modified] Pin
George_George5-Jun-06 2:24
George_George5-Jun-06 2:24 
GeneralRe: confused about system stack [modified] Pin
Viorel.5-Jun-06 3:18
Viorel.5-Jun-06 3:18 
GeneralRe: confused about system stack [modified] Pin
George_George5-Jun-06 3:38
George_George5-Jun-06 3:38 
GeneralRe: confused about system stack [modified] Pin
Viorel.5-Jun-06 3:58
Viorel.5-Jun-06 3:58 
GeneralRe: confused about system stack [modified] Pin
George_George6-Jun-06 19:07
George_George6-Jun-06 19:07 
GeneralRe: confused about system stack [modified] Pin
Viorel.6-Jun-06 20:58
Viorel.6-Jun-06 20:58 
GeneralRe: confused about system stack [modified] Pin
George_George6-Jun-06 21:21
George_George6-Jun-06 21:21 
QuestionQuaternion rotation Pin
lastgen4-Jun-06 22:43
lastgen4-Jun-06 22:43 
Questionhow to structure my program?? Pin
Nawar_nrr4-Jun-06 22:41
Nawar_nrr4-Jun-06 22:41 
AnswerRe: how to structure my program?? Pin
Blake Miller6-Jun-06 5:07
Blake Miller6-Jun-06 5:07 
Questionevent socket model question Pin
followait4-Jun-06 22:14
followait4-Jun-06 22:14 
GeneralRe: Does event socket model have to wait for events in another thread in an interactive app? [modified] Pin
Sarath C4-Jun-06 22:25
Sarath C4-Jun-06 22:25 
GeneralRe: Does event socket model have to wait for events in another thread in an interactive app? [modified] Pin
followait4-Jun-06 22:50
followait4-Jun-06 22:50 
QuestionStrange spin button control problem Pin
David L.S.4-Jun-06 21:33
David L.S.4-Jun-06 21:33 
AnswerRe: Strange spin button control problem Pin
PJ Arends4-Jun-06 21:54
professionalPJ Arends4-Jun-06 21:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.