The question arose during the study of PC architecture. What type of memory is a stack? A stack is an abstract data type that tells a wiki, but about where it is stored a word. I have come to the fact that the stack can be either a universal register or be created in RAM, but RAM is not intended for this. Who knows can share knowledge, and then the question is haunted
- And what do you think of your RAM? It is needed to store any operational data, including the program code itself and its regular data and stack. Actually, the stack differs from ordinary data only by the presence of a pointer to its top and the method of working with this pointer - Mike
- Well, in fact, yes, Ram gives a place for the program, and the program allocates itself a place for the stack. It seems so logical turns. @Mike thanks - Volodymyr Samoilenko
- Well, let's say on the x86 platform, the stack for the program is created by the operating system, at least by the fact that this memory is specially marked in the segment descriptors that are completely under the control of the OS. But the operating system as the first startup program defines it to itself of course - Mike
1 answer
If you speak of a stack as a storage of procedure parameters and their local variables, then yes, it is stored in random access memory (RAM), where else?
If you speak of a stack as a data structure that is available in some languages, then the storage location is a stack in the sense of the previous paragraph or a heap, depending on many factors. For example, std::stack from C ++ is stored, like any object, where it is allocated, but most likely it stores its data in a heap. In any case, it is also in RAM.
Finally, if we talk about the stack as an abstract data structure, then its implementation can be stored anywhere - for example, in the file system. Depends only on the desire of the developer implementation.
- just the register is also suitable for his requests, fast, small and for example a universal register is well suited for storing the result or address, but then he remembered that the stack can be stretched to 1 megabyte using recursion, and such dimensions are not comprehensible to registers, so I was stupid - Volodymyr Samoilenko
- @VladimirSamoilenko: In registers, you can store a dozen numbers, and the stack can grow as you like. Therefore, in the registers you can keep a maximum pointer to the stack, and the stack itself will have to be put in the RAM anyway. - VladD
- Thank you, figured out - Volodymyr Samoilenko
- @VladimirSamoilenko: Please! - VladD