什么是内存堆?
当前回答
它是进程使用的内存管理器从操作系统分配的内存块。然后调用malloc()等从这个堆中获取内存,而不必直接处理操作系统。
其他回答
every running process has its own private fake virtual memory provided by the OS. the OS can map this to physical memory at any point as long as it is available otherwise it will map to disk and swap as needed. this virtual memory is logically divided into segments for organizing different kinds of data. the code segment holds the executable instructions. the data segment holds static data such as global or static variables. the stack holds local data that is automatically managed by called and returning functions. all of these segments are fixed size even the stack its just the portion used can grow or shrink and is reclaimed as functions returned. the only segment that is not preallocated at app startup and fixed size is the heap. the app can request from the OS at runtime new memory to be allocated and the OS will reserve a part of your apps virtual space and commit that to physical memory as needed. the OS will return a pointer to that newly allocated heap memory and that pointer holds the base or starting address of the new block. that pointer sits on the stack and when that stack space is reclaimed your pointer will be no longer in scope and therefore you have no means of access to that block of memory. and if you dont tell the OS you are done with it so it can reclaim it that is just zombie memory sitting there with no means of access and if your app keeps requesting memory while never giving it back it will crash when the system runs out of memory. so it is important to free or at least pass the pointer to another pointer external to the scope it was defined in so you can maintain an interface to that memory allocated in heap space. i would suggest looking into virtual memory further and understanding segments.
内存堆是保存动态分配内存的常用结构。 参见维基百科上的Dynamic_memory_allocation。
还有其他结构,比如水池、堆栈和堆。
内存组织分为两部分:堆内存和堆栈内存。
堆内存是主工作内存,最低地址是起始地址。
在堆栈内存中,数据流是由自下而上的方法驱动的。然后内存Arch被命名为stack。
A memory heap is a location in memory where memory may be allocated at random access. Unlike the stack where memory is allocated and released in a very defined order, individual data elements allocated on the heap are typically released in ways which is asynchronous from one another. Any such data element is freed when the program explicitly releases the corresponding pointer, and this may result in a fragmented heap. In opposition only data at the top (or the bottom, depending on the way the stack works) may be released, resulting in data element being freed in the reverse order they were allocated.
它是进程使用的内存管理器从操作系统分配的内存块。然后调用malloc()等从这个堆中获取内存,而不必直接处理操作系统。