Click here to Skip to main content
16,004,836 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MessageBoxW and converting to LPCWSTR Pin
sawerr4-Sep-06 23:27
sawerr4-Sep-06 23:27 
GeneralRe: MessageBoxW and converting to LPCWSTR Pin
prasad_som4-Sep-06 23:27
prasad_som4-Sep-06 23:27 
GeneralRe: MessageBoxW and converting to LPCWSTR Pin
Milton Karimbekallil4-Sep-06 23:35
Milton Karimbekallil4-Sep-06 23:35 
QuestionUse of Select Option in Socket. Pin
uday kiran janaswamy4-Sep-06 22:47
uday kiran janaswamy4-Sep-06 22:47 
AnswerRe: Use of Select Option in Socket. Pin
_AnsHUMAN_ 4-Sep-06 23:16
_AnsHUMAN_ 4-Sep-06 23:16 
QuestionDifference in Heap and Stack. Pin
uday kiran janaswamy4-Sep-06 22:41
uday kiran janaswamy4-Sep-06 22:41 
AnswerRe: Difference in Heap and Stack. Pin
_AnsHUMAN_ 4-Sep-06 23:03
_AnsHUMAN_ 4-Sep-06 23:03 
GeneralRe: Difference in Heap and Stack. Pin
Steve S4-Sep-06 23:19
Steve S4-Sep-06 23:19 
_AnShUmAn_ wrote:
It's a difference of access memory (the hardware of the memory). The stack is much faster than the heap, but smaller and more expensive. primitives are place in the stack, but objects on the heap.


Really? I always thought memory was memory!
Using the stack is generally faster than the heap, since you don't have the overhead of managing a pool of memory. Individual allocations of stack memory cannot be freed, since it's done on a 'frame' basis, and everything in the current frame is cleaned up (albeit sequentially).

In the snippet

CDialog d;

the object itself is stack-based, and will automatically have it's destructor called when the function returns (as the object will go out of scope).

In the snippet

CDialog* d = new CDialog;

the variable is stack-based, but the object itself is on the heap. When the function completes, the variable that refers to the object goes out of scope, but the object still exists, as you say. It will not have a destructor called automatically.

There is, AFAICR, nothing which forces primitives to live on the stack, and force objects to be allocated on the heap. Usually the developer decides, particularly in the situation of developing for Windows, where UI objects need to exist beyond the lifetime of a function.

Steve S
Developer for hire

GeneralRe: Difference in Heap and Stack. Pin
uday kiran janaswamy4-Sep-06 23:32
uday kiran janaswamy4-Sep-06 23:32 
GeneralRe: Difference in Heap and Stack. Pin
_AnsHUMAN_ 5-Sep-06 1:12
_AnsHUMAN_ 5-Sep-06 1:12 
GeneralRe: Difference in Heap and Stack. Pin
Steve S5-Sep-06 1:45
Steve S5-Sep-06 1:45 
GeneralRe: Difference in Heap and Stack. Pin
_AnsHUMAN_ 5-Sep-06 2:09
_AnsHUMAN_ 5-Sep-06 2:09 
QuestionAbout the drag&drop Pin
lj_wml4-Sep-06 22:28
lj_wml4-Sep-06 22:28 
AnswerRe: About the drag&drop Pin
Michael Dunn5-Sep-06 12:46
sitebuilderMichael Dunn5-Sep-06 12:46 
GeneralRe: About the drag&drop Pin
lj_wml5-Sep-06 16:02
lj_wml5-Sep-06 16:02 
Questionmake setup Pin
milleusi4-Sep-06 22:08
milleusi4-Sep-06 22:08 
AnswerRe: make setup Pin
Hamid_RT5-Sep-06 2:36
Hamid_RT5-Sep-06 2:36 
GeneralRe: make setup Pin
milleusi5-Sep-06 7:19
milleusi5-Sep-06 7:19 
GeneralRe: make setup Pin
Hamid_RT5-Sep-06 20:35
Hamid_RT5-Sep-06 20:35 
QuestionNeed help on socket progrmming Pin
Kiran Pinjala4-Sep-06 21:55
Kiran Pinjala4-Sep-06 21:55 
AnswerRe: Need help on socket progrmming Pin
Frank K5-Sep-06 1:24
Frank K5-Sep-06 1:24 
Questioncan i post a Completion MSG from one IOCP to another? Pin
houpainansheng4-Sep-06 21:40
houpainansheng4-Sep-06 21:40 
Questionhow to save data in database Pin
With_problem4-Sep-06 21:02
With_problem4-Sep-06 21:02 
AnswerRe: how to save data in database Pin
Hamid_RT5-Sep-06 0:59
Hamid_RT5-Sep-06 0:59 
GeneralRe: how to save data in database Pin
With_problem5-Sep-06 19:11
With_problem5-Sep-06 19:11 

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.