Stack-Based mostly Memory Allocation
페이지 정보
작성자 BI 작성일25-08-16 08:06 (수정:25-08-16 08:06)관련링크
본문
Stacks in computing architectures are areas of memory where data is added or eliminated in a final-in-first-out (LIFO) manner. In most modern computer programs, each thread has a reserved region of memory referred to as its stack. When a function executes, it could add some of its local state data to the highest of the stack; when the function exits it is answerable for eradicating that information from the stack. At a minimal, a thread's stack is used to store the situation of a return deal with provided by the caller so as to permit return statements to return to the proper location. The stack is usually used to store variables of mounted size native to the at present active features. Programmers may further select to explicitly use the stack to store native data of variable length. If a area of memory lies on the thread's stack, that memory is said to have been allocated on the stack, i.e. stack-primarily based memory allocation (SBMA).
This is contrasted with a heap-primarily based memory allocation (HBMA). The SBMA is commonly carefully coupled with a operate name stack. Because the information is added and removed in a final-in-first-out method, stack-based memory allocation is quite simple and usually much quicker than heap-based mostly memory allocation (often known as dynamic Memory Wave allocation) e.g. C's malloc. One other feature is that memory on the stack is routinely, and very effectively, reclaimed when the perform exits, which may be handy for the programmer if the info is not required. If, however, the info must be kept in some kind, then it have to be copied from the stack to the heap earlier than the function exits. Due to this fact, stack based mostly allocation is appropriate for temporary knowledge or information which is now not required after the current function exits. A thread's assigned stack measurement will be as small as just a few bytes on some small CPUs. Allocating extra memory on the stack than is available can result in a crash on account of stack overflow.
댓글목록
등록된 댓글이 없습니다.

