c++ - Stack Memory vs Heap Memory -


possible duplicate:
what , stack , heap

i programming in c++ , wondering stack memory vs heap memory. know when call new, memory heap. if if create local variables, memory stack. after research on internet, common answer stack memory temporary , heap memory permanent.

is stack , heap memory model concept of operating system or computer architecture? of might not follow stack , heap memory model or of them follow it?

stack , heap memory abstraction on memory model of virtual memory ( might swap memory between disk , ram). both stack , heap memory physically might ram or disk? reason heap allocation seems slower stack counterpart?

also, main program run in stack or heap?

also, happen if process run out of stack memory or heap memory allocated?

thanks

stack memory range of memory accessible via stack register of cpu. stack used way implement "jump-subroutine"-"return" code pattern in assembly language, , means implement hardware-level interrupt handling. instance, during interrupt, stack used store various cpu registers, including status (which indicates results of operation) , program counter (where cpu in program when interrupt occurred).

stack memory consequence of usual cpu design. speed of allocation/deallocation fast because strictly last-in/first-out design. simple matter of move operation , decrement/increment operation on stack register.

heap memory memory left on after program loaded , stack memory allocated. may (or may not) include global variable space (it's matter of convention).

modern pre-emptive multitasking os's virtual memory , memory-mapped devices make actual situation more complicated, that's stack vs heap in nutshell.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -