C ++, Free-Store vs Heap

Dynamic allocations with new/delete are called free-store , and heap is used in malloc/free operations.

I would like to know if there is a real difference in practice.
Do compilers split between these two terms? (Free store and heap, not new/malloc )

+100
c ++ memory-management
Aug 29 '09 at 8:05
source share
7 answers

See http://www.gotw.ca/gotw/009.htm ; he can describe the differences between heap and free storage much better than I could:

Free shop:

A free store is one of two dynamic memory areas allocated / deallocated using new / delete. The service life of an object may be less than the storage time allocated; that is, the objects of a free store can be allocated memory without being immediately initialized and can be destroyed without being immediately freed. During the storage period, but outside the lifetime of the object, access to the storage is controlled through the void *, but there is no proto-object non-static members or members can be accessed, their addresses, or otherwise manipulated.

Heap:

A heap is another dynamic memory area allocated / freed by malloc / free and their variants. Please note that while the global new default and delete can be implemented from the point of view of malloc and the free compiler, the heap is not the same as free storage and the memory allocated in one area cannot be safely freed up in another. The memory allocated from the heap can be used for objects of class type by placement - new construction and explicit destruction. If it is used, apply notes about the life of a free store in the same way here.

+67
Aug 29 '09 at 8:15
source share

For C ++, the difference between free storage and heap has become purely conceptual. As a jar for collecting errors, and one for collecting cookies. One is marked one way, the other the other. This designation is intended to bring home to the point that you NEVER mix "new" and "delete" with "malloc", "realloc" or "free" (or, for example, bit levels).

During the interviews, it’s good to say that “the new and the remote use the free store, malloc and the free use of the heap, the new and remote calls to the constructor and destructor, respectively, however malloc and free do not.” However, you often hear that memory segments are indeed in the same area, however CAN may be specific to the compiler, that is, it is possible that both can designate different memory spaces as pools (not sure why this would be , though).

+47
Feb 08 2018-12-12T00:
source share

Mike Koval answers pretty well. In practice, however, they are almost always the same memory area - in most cases, if you delve into the new compiler implementation, you will find that it calls malloc() .

In other words: from the point of view of the machine, the heap and the free magazine are one and the same. A difference exists inside the compiler.

To make things even more confusing, before C ++ we said “heap” means what is now called “free storage”.

+18
Aug 29 '09 at 8:19
source share

The term heap may also refer to a particular data structure, but in the context of Call malloc, free, new, and delete operations, the terms heap and free store are used more or less interchangeably.

+2
Aug 29 '09 at 8:14
source share

The heap and free-store should not be compatible. In a limited context, as in 8-bit AVR microcontrollers with the standard C ++ 11 library, they cannot be used even in one program. Free storage and heap perform their allocations in the same memory space, overwriting each other's structures and data. In this context, the Free store is different and incompatible with Heap because the “new storage library / remove free storage” is easier (and faster) than the “Malloc / free / realloc / calloc heap library” and thus provides a huge increase in memory usage for C ++, a built-in programmer (in a context where you have only 512 bytes of RAM).

See the 8-bit C ++ 11/14 Standard Library at https://github.com/ambroise-leclerc/ETL/tree/master/libstd.

+2
May 3 '14 at 9:02
source share

I don’t remember the standard that ever mentioned a bunch of words, except for descriptions of heap functions like push_heap et al. All dynamic allocations are performed in free storage.

+1
Aug 29 '09 at 8:09
source share

The Free Store is a pool of unallocated heap memory assigned to a program that the program uses to dynamically allocate during program execution. Each program has a pool of unallocated heap memory that it can use at run time. This pool of available memory is called free storage for the program. Dedicated free store memory is not called.

0
Jan 11 '17 at 13:53 on
source share



All Articles