Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ C ++ free store and heap     - CentOS 6.5 platform offline compile and install PHP5.6.6 (Server)

- Advanced Linux security settings (Linux)

- Oracle 11g RAC automatically play GI PSU patch (11.2.0.4.8) (Database)

- Java object serialization and deserialization (Programming)

- VSFTPD Security (Linux)

- CentOS7 + Redis Live Installation and Configuration (Linux)

- Linux Basics Tutorial: create your own Vim IDE (Linux)

- Zabbix monitoring disk IO status (Server)

- Linux system performance monitoring with Nmon (Linux)

- Android judgment toward camera pictures (Programming)

- How to Install Xombrero 1.6.4 (minimalist Web browser) on Ubuntu and Archlinux (Linux)

- Disk partition MBR (Linux)

- Ubucompilator-Ubuntu, Debian, Linux Mint created deb package of graphical tools (Linux)

- Java memory analysis tool uses detailed MAT (Programming)

- Linux command execution order control and pipeline (Linux)

- Linux bash: scp: command not found the problem (Linux)

- MySQL5.7 implement virtual column expression index (Database)

- Linux atomic operations and synchronization mechanisms (Programming)

- Linux system security check method (Linux)

- MySQL master-slave database configuration and error handling Raiders (Database)

 
         
  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:      
 
- VirtualBox 4.3 Can not open a new task for a virtual computer solution (Linux)
- Memory leak analysis using Android studio (Programming)
- To configure linux transparent firewall (Linux)
- GoldenGate for Oracle data consistency initializing (Database)
- Thinking in Java study notes - Generics (Programming)
- Using RAID in Linux: Create a RAID 5 (Linux)
- PSUADE installation under Linux (Linux)
- To solve the Mac in question invalid BASH under configuration environment variable (Linux)
- How do you temporarily emptied Bash environment variable before running the command on Linux (Linux)
- Ubuntu install Eclipse can not find JAVA_HOME problem (Linux)
- AIX system file security aspects (Linux)
- Linux, Firefox unloading and installation and upgrade (Linux)
- Based LNMP + uWSGI deploy Django applications (Server)
- Repair Chrome for Linux is (Linux)
- Hadoop safe hftp (Server)
- Oracle 11g partition maintenance (two) - Coalescing Partitions (Database)
- ThinkPad X220 Ubuntu 14.10 installed on fingerprint recognition (Linux)
- Using a proxy method under Linux terminal (Linux)
- Examples of safety testing system notes for RedHat Linux (Linux)
- Zabbix monitors Nginx status (Server)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.