What is the technical definition of “dynamic storage” in C++ [duplicate]

别说谁变了你拦得住时间么 提交于 2019-12-25 18:54:22

问题


Just what the title says, "What is the technical definition of dynamic storage in C++?" I'm curious as to how to discuss dynamic memory allocation on the heap without making any mistakes in my explanation.


回答1:


From the The C++ Programming Language: Special Edition

Free store, from which memory for objects is explicitly requested by the program and where a program can free memory again once it is done with it (using new and delete ). When a program needs more free store, new requests it from the operating system. Typically, the free store (also called dynamic memory or the heap) grows throughout the lifetime of a program because no memory is ever returned to the operating system for use by other programs.




回答2:


Detailed Explaination

The heap is a bunch of memory that can be used dynamically.

Lets say you want 12kb of memory for an object then the dynamic allocator will look through its list of free space in the heap, pick out a 12kb chunk, and give it to you.

Generally, the dynamic memory allocator (malloc, new, etc.) starts at the end of memory and works backwards.



来源:https://stackoverflow.com/questions/34550025/what-is-the-technical-definition-of-dynamic-storage-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!