- 스택 메모리 만 있고 힙 메모리가 없으면 문제는 무엇이 생성됩니까? 나는 그것이 프로그램을 매우 빠르게 만들 것이라고 생각한다.
- 개체가 힙 메모리에서 만들어지는 것을 알고 있습니다. 개체가 스택 메모리에 만들어지면 문제는 무엇입니까? 왜 힙 메모리를 만들었습니까?
읽었습니다.1. 왜 스택 메모리의 크기가 고정되어 있습니까?
스택
very fast access
don't have to explicitly de-allocate variables
space is managed efficiently by CPU, memory will not become fragmented
limit on stack size (OS-dependent)
힙
variables can be accessed globally
no limit on memory size
(relatively) slower access
no guaranteed efficient use of space, memory may become fragmented over time as blocks of memory are allocated, then freed
you must manage memory (you're in charge of allocating and freeing variables)
variables can be resized using realloc()
스택이 힙보다 액세스가 빠르다는 생각은 부분적으로 사실입니다. 스택에 * 공간을 할당하는 것이 힙 메모리를 할당하는 것보다 빠르다는 것이 사실이지만, 그 후에 메모리 액세스는 메모리 액세스입니다.스택의 현재 상단에 가까운 것이 캐시에있을 가능성이 높지만 스택에 많은 것을 할당하면 그 혜택도 사라집니다. –