Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ free store and heap     - Linux virtual machines to solve end MySQL database can not remote access (Database)

- Use Visual Studio 2015 to develop Android program (Programming)

- Dell R710 server disk recovery database one case (record) (Server)

- CentOS7 boot systemd introduction and use of management (Linux)

- Unable to solve the official version of Android Studio online update problem (Linux)

- CentOS 6.5 installation Python3.0 (Linux)

- Swift 2.0 brief (Linux)

- Java data structures - order linear form of table ArrayList (Programming)

- Formatted output printf command (Programming)

- Linux under DB2SQL1024N A database connection does not exist. SQLS (Database)

- PostgreSQL 9.3.2 Json type of use (Database)

- Oracle 10046 Event (Database)

- Nonstandard IMP-00010 error processing one case (Database)

- Linux kernel modules related to the management Comments (Linux)

- Hanoi problem Java Solution (Programming)

- CentOS 7 source code to compile and install PHP5.6 Nginx1.7.9 and MySQL (LNMP build environment) (Server)

- How to install the client sqlplus under linux (Database)

- How to download GOG games in Linux command line (Linux)

- Help you to see Linux system architecture type 5 Common Commands (Linux)

- Linux System Getting Started Tutorial: how to find information on Linux-embedded module (Linux)

 
         
  C ++ free store and heap
     
  Add Date : 2018-11-21      
         
         
         
  "Free store" VS "heap"

When I asked your C ++ memory layout, you would probably answer:

"In C ++, the memory area is divided into five areas, namely the heap, stack, free store, global / static storage area, the constant storage area."

If I then asked you free store and stack What is the difference, you might answer:

"Malloc a block of memory allocated on the heap, free use of free memory, while the new memory is applied on the free store, use delete to release."

This sounds true, but if I then asked:

Free store and heap are two distinct areas of memory it? They may do the same?

You may be senseless.

In fact, I see a lot of the Internet blog, free store division of the heap is the dividing line between new / delete and malloc / free. However, although the C ++ standard does not require, but many compilers new / delete are in malloc / free basis to achieve. So I ask: malloc so as to achieve new, the allocated memory on the heap or on the free store?

Technically, the heap (heap) is a C language and operating system terminology. Operating system stack is maintained by a special memory, which provides dynamic allocation function, when you run the program calls malloc () which will be allocated later may call free the memory return. The free store is a C ++ abstraction by new and delete objects dynamically allocate and release memory region through new applications may be referred to the free store. Basically, all the C ++ compiler default heap memory to achieve freedom, that is the default global operator new and delete might follow malloc and free way to be implemented by the new operator then allocated objects , it also heap, it is also on the free store correctly. However, programmers can also overload operators, use other free storage memory to achieve, such as global variables do object pooling, when the free store is distinguished from a heap. We need to remember is this:

Heap is the operating system maintains a memory, and free memory in C ++ new and delete through dynamic allocation and release of the object abstraction. Heap and the free store is not equivalent.

Source of problems

Then come back to take a look at the origin of the problem lies. The first time we use the C language, and there is no such controversy, it is clear to know malloc / free in the heap for memory operations. Until we see several free store (free store) in Bjarne Stroustrup's book, to be honest, I have been equivalent to the free store heap. In Herb Sutter's "exceptional C ++" expressly stated that the free store (free store) and heap (heap) is different. Discussions on the free store and stack are equivalent problems probably started from here:

Free Store
The free store is one of the two dynamic memory areas, allocated / freed by new / delete Object lifetime can be less than the time the storage is allocated;. That is, free store objects can have memory allocated without being immediately initialized, and can be destroyed without the memory being immediately deallocated. During the period when the storage is allocated but outside the object's lifetime, the storage may be accessed and manipulated through a void * but none of the proto-object's nonstatic members or member functions may be accessed, have their addresses taken, or be otherwise manipulated.

Heap
The heap is the other dynamic memory area, allocated / freed by malloc / free and their variants. Note that while the default global new and delete might be implemented in terms of malloc and free by a particular compiler, the heap is not the same as free store and memory allocated in one area can not be safely deallocated in the other. Memory allocated from the heap can be used for objects of class type by placement-new construction and explicit destruction. If so used, the notes about free store object lifetime apply similarly here.

The authors also pointed out that the reason for the heap and the free store to come apart, because the C ++ standard draft about whether these two regions linked issues has been very careful not to give a detailed description and specific situations are new and delete according to malloc and free to achieve, or is put over the malloc and free are in accordance with the new and delete realized also inconclusive. Different mode of operation of these two memory areas, different access methods, so it should not be treated as the same thing to use.

in conclusion

Free store in C ++ by new and delete dynamic allocation and release objects abstraction, but Heap (heap) is a C language and operating system terminology, is the operating system maintains a dynamic memory allocation.

New memory area of ​​the application referred to in C ++ free store. With the heap implementation of free storage, it can be said that the application of new memory area on the heap.

Heap and free store there are differences, they are not equivalent.

If you come from the C language, C ++ never come into contact; or you start a free store concept familiar to C ++, but never heard of malloc C language, maybe you will not fall into the "free store like the same heap , it seemed different "such confusion among. It's like Bjarne Stroustrup said:

usually because they come from a different language background.
     
         
         
         
  More:      
 
- Linux VMware virtual machine after the cloning of the card can not start to solve (Linux)
- Distributed Firewall Design on Linux platform (Linux)
- Linux (RHEL6 CENTOS6 OLE6) VNC-SERVER Installation and Configuration (Server)
- The SVN installation, configuration and start - up under Linux (CentOS 6.5) (Server)
- sed and awk in shell usage and some examples (Linux)
- Linux Shell Scripting multithreading (Programming)
- C ++ Supplements --new delete overload (Programming)
- CentOS system Amoeba + MySQL Master-slave configuration (Database)
- How to protect your eyes automatically adjust the screen brightness on Linux (Linux)
- Linux / Unix system-level IO (Linux)
- Depth understanding of the use of Spring Redis (Programming)
- MyCAT read and write separation of MySQL (Database)
- Setting Linux desktop environment, achieve HiDPI display support (Linux)
- The Objects in JavaScript (Programming)
- CentOS7 installation hardware monitoring for Zabbix enterprise applications (Server)
- Java static code analysis tool Infer (Programming)
- Lazarus for Raspbian installation (Linux)
- RAID disk array Description (Linux)
- systemd run levels and service management command Introduction (Linux)
- MySQL Study of --Percona Server 5.5 Upgrade 5.6 (Database)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.