Process's address space and heap

Typically, in each process, the virtual memory available to that process is called its address space. Each process‘s address space is typically organized in 6 sections that are illustrated in the next picture: environment section - used to store environment variables andcommand line arguments; the stack, used to store memory for function arguments, return values, and automatic variables; the heap (free store) used for dynamic allocation, two data sections (for initialized and uninitialized static and global variables) and a text section where the actual code is kept.

Heap is the area of memory in which objects with dynamic extent are allocated. The lifetime of object is greater than the lifetime of the procedure that creates it. This object is said to have dynamic extent.

The Heap

To understand why the dynamic memory allocation is time consuming let‘s take a closer look at what is actually happening. The memory area where new gets its blocks of memory for allocation (usually called free store or heap) is illustrated in the following picture:

When new is invoked, it starts looking for a free memory block that fits the size for your request. Supposing that such a block of memory is found, it is marked as reserved and a pointer to that location is returned. There are several algorithms to accomplish this because a compromise has to be made between scanning the whole memory for finding the smallest free block bigger than the size of your object, or returning the first one where the memory needed fits. In order to improve the speed of getting a block of memory, the free and reserved areas of memory are maintained in a data structure similar to binary trees called a heap. The various algorithms for finding free memory are beyond the scope of this article and you can find a thorough discussion about them in D. Knuth‘s monographThe Art of Computer Programming -- Vol.1, Fundamental Algorithms). This overhead combined with the risk for memory leaks makes the use of automatic memory (allocated on the stack) preferred whenever possible and the allocation is not large.

参考文献:

http://www.cprogramming.com/tutorial/virtual_memory_and_heaps.html

Process's address space and heap

时间: 2024-07-30 05:23:08

Process's address space and heap的相关文章

Memory Layout (Virtual address space of a C process)

Memory Layout (Virtual address space of a C process) 分类: C语言基础2012-12-06 23:16 2174人阅读 评论(0) 收藏 举报 found a good example to demostrate the memory layout and its stack info of a user-mode process, only that this example is for Linux. But it is still wo

System and method for critical address space protection in a hypervisor environment

A system and method in one embodiment includes modules for detecting an access attempt to a critical?address?space?(CAS) of a guest operating system (OS) that has implemented?address?space?layout?randomization?in a hypervisor environment, identifying

Method of address space layout randomization for windows operating systems

A system and method for?address?space?layout?randomization?("ASLR") for a Windows operating system is disclosed. The?address?space?layout?includes one or more memory regions that are identified and then a particular implementation of the system

Method for address space layout randomization in execute-in-place code

The present application relates generally to laying out?address?space for execute-in-place code and, more specifically, to a method for address?space?layout?randomization?for such code. Ahead of executing a program, executable code for which is store

Multiple address space mapping technique for shared memory wherein a processor operates a fault handling routine upon a translator miss

Virtual addresses from multiple address spaces are translated to real addresses in main memory by generating for each virtual address an address space identifier (AID) identifying its address space. Then, the virtual address and its AID are used to o

ARM32 Linux kernel virtual address space

http://thinkiii.blogspot.jp/2014/02/arm32-linux-kernel-virtual-address-space.html The 32-bit ARM CPU can address up to 2^32 = 4GB address*. It's not big enough in present days, since the size of available DRAM on computing devices is growing fast and

ASLR(Address space layout randomization)地址空间布局随机化

/*********************************************************************  * Author  : Samson  * Date    : 12/07/2014  * Test platform:  *              3.13.0-24-generic  *              GNU bash, 4.3.11(1)-release  * ************************************

KEIL C 出现ADDRESS SPACE OVERFLOW的解决办法

ERROR L107: ADDRESS SPACE OVERFLOW 用KEIL选用small模式编译一个程序时老时出错,信息如下. *** ERROR L107: ADDRESS SPACE OVERFLOW ... ... Program Size: data=217.6 xdata=0 code=5314 Target not created 芯片我选的是AT89C52,RAM有256呀,怎么会OVERFLOW呢? 但是如果编译模式选用Compact或large时就一切正常. ... ..

Difference between Process and thread?

What are the differences between a process and a thread? How are they similar? How can 2 threads communicate? How can 2 process communicate? Both processes and threads are independent sequences of execution. The main difference is that threads (of th