Stack 과 Heap은 무엇이고 어디에 있나요??

LONGNEW·2020년 12월 30일
0

StackOverFlaw

목록 보기
6/16

https://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap

Q. What and where are the stack and heap?


The stack is the memory set aside as scratch space for a thread of execution.
Stack은 현재 실행되고 있는 Thread의 Scratch space(Scratch space is space on the hard disk drive that is dedicated for storage of temporary user data.)에 존재하는 메모리입니다.
When a function is called, a block is reserved on the top of the stack for local variables and some bookkeeping data.
함수를 호출 했을 때, 지역 변수와 데이터를 스택의 최상단에 저장합니다.
When that function returns, the block becomes unused and can be used the next time a function is called.
함수가 리턴 할때, 데이터를 담고 있던 블럭은 다시 사용되지 않았던 상태로 돌아가고 다음에 함수가 호출 될 때 다시 이용됩니다.
The stack is always reserved in a LIFO (last in first out) order; the most recently reserved block is always the next block to be freed.
스택에 저장될 때는 언제나 LIFO순서로 입력이 됩니다. 가장 최근에 저장된 블럭은 다음 수행될 때 사용되지 않았던 상태로 돌아갈 블럭입니다.
This makes it really simple to keep track of the stack; freeing a block from the stack is nothing more than adjusting one pointer.
이것이 스택을 트래킹 하기 쉽게 만듭니다. 블럭을 원상태로 되돌리는 것은 한개의 포인터를 조절하는 것으로 수행이 가능합니다.

The heap is memory set aside for dynamic allocation.
Heap은 메모리 셋을 동적으로 할당하는 것입니다.
Unlike the stack, there's no enforced pattern to the allocation and deallocation of blocks from the heap;
Stack과 다르게, 메모리를 할당, 반납시에 필수적인 패턴이 존재하지 않습니다.
you can allocate a block at any time and free it at any time.
언제든 블럭에 할당할수 있고, 반납할 수 있습니다.
This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time;
이러한 이유로 어떤 시간에 메모리 상황을 파악하려 할 때, 트래킹 하는 것이 복잡합니다.
there are many custom heap allocators available to tune heap performance for different usage patterns.
여러가지 커스텀된 할당 방법이 존재합니다. 이는 여러 사용 패턴에 대한 Heap의 성능을 조절해줍니다.
Each thread gets a stack, while there's typically only one heap for the application (although it isn't uncommon to have multiple heaps for different types of allocation).
프로그램을 실행할 때 1개의 heap만을 이용하는데 이때 각 Thread는 stack 한 개를 이용합니다.

0개의 댓글