You are on page 1of 21

Topic Heap management.

Subject: Compiler Theory

Presented to:

Sir Fahad

Presented by:

Naila, Iqra, Saira,Saba

The heap is the portion of the store that is used for data that lives indefinitely, or until the program explicitly deletes it. The objects whose existence is not tied to the procedure activation that creates them are stored on a heap.

A request for heap space may be explicit or implicit. An explicit request involves a call to a routine like new or malloc. The expression Str1 + Str2creates a new string representing the catenation of strings Str1 and Str2. There is no compile-time bound on the sizes of Str1 and Str2, so heap space must be implicitly allocated to hold the newly created string.

It

is the subsystem that allocates and deallocates space within the heap. The memory manager keep track of all the free space in heap storage at all times.
It

performs two basic functions: Allocation Deallocation

Memory

management would be simpler if

All allocation requests were for chunks of the same size, Storage were released predictably

Space

efficiency A memory manager should minimize the total heap space needed by a program. Program Efficiency By attention to the placement of objects in memory Low Overhead Minimize the overhead

o o

A processor has a small number of registers, it has one or more levels of cache(usually made out of static (RAM). The next level of hierarchy is the physical (main) memory,(made out of dynamic RAM). The machine first looks for the data in the closest.

Energy leaks out quickly. So to keep information in dynamic RAM, your computer needs to recharge all the cells in the memory chip every few milliseconds, or all the data is lost. Static RAM never needs to be refreshed, it uses less power and operates much more quickly. But its much more expensive to manufacture. The most common form of RAM in a computer is dynamic RAM.

Temporal locality If the memory locations it accesses are likely to be accessed again within short period of time. Spatial locality

If the memory locations close to the location accessed are likely also to be accessed within short period of time.

Fragmentation of a very large heap space commonly forces us to include some form of reuse of heap space.

The

heap allocator must search the free space list for a block of sufficient size. There are many search strategies that might be used: Best fit First fit Next fit

Best

Fit The free space list is searched for the free block that matches most closely the requested size. This minimizes wasted heap space, the search may be quite slow.

First

Fit The first free heap block of sufficient size is used. Unused space within the block is split off and linked as a smaller free space block.

Next Fit This is a variant of first fit in which succeeding searches of the free space list begin at the position where the last search ended. The idea is to cycle through the entire free space list rather than always revisiting free blocks at the head of the list.

It is possible to combine a chunk(which is deallocated by an object) with adjacent chunks of the heap, to form a larger chunk. The advantage to doing so is that a large chunk can do work of a small chunk, but many smaller chunks cannot hold a larger object.

Boundary

Tags: Each chunk has vital information at both ends (free/allocated). Doubly Linked: Each chunk contains the next-node link, a second link field pointing to the previous node in the sequence. The two links may be called forward(s) and backwards, or next and previous.

Allocating heap space is fairly easy. Sometimes we may never need to Deallocate! If heaps objects are allocated infrequently or are very long-lived, deallocation is unnecessary. We simply fill heap space with in use objects.

memory leak is a portion of heap memory that was allocated but not freed. Typically, the elimination of a memory leak is critical for applications that run continuously because even a single byte leak can crash a mission critical application that runs over time.

Thanks

You might also like