Explicit Memory Management

Explicit Memory Management - • Sbrk(s increases the size...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Explicit Memory Management In explicit memory management a program frees objects by calling free/delete explicitly The program uses a “malloc library” usually provided by the C standard library libc. Memory is requested from the OS and added to a free list. Subsequent requests are satisfied from memory from the free list. Free/delete returns memory to the free list.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Explicit Memory Management Memory is requested to the OS in big chunks (8KB). This decreases the number of times that memory is requested from the OS Also, it is difficult to return memory to the OS since the OS handles memory in pages and memory allocator handle memory in bytes.
Background image of page 2
Explicit Memory Management OS Malloc Library Program malloc/new Free/delete sbrk(s),mmap sbrk(-s),munmap (not very common)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Explicit Memory Management When the memory allocator runs out of memory in the free list it calls sbrk(s).
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: • Sbrk(s) increases the size of the heap by s bytes. • Sbrk retuns a pointer to the old heap limit. • You can decrease the size of the heap by passing a negative size to sbrk. This will shrink the heap. Explicit Memory Management Heap BSS Data Text sbrk(s) s Explicit Memory Management • An alternative to sbrk() is to use mmap with an anonymous mapping. • This will return a group of pages initialized with 0’s. • You can return memory to the OS by using munmap. Explicit Memory Management • Returning memory back to the OS is defficult because: – Sbrk only can return memory to the OS if it happens to be at the end of the heap. – Munmap can return memory to the OS if whole pages are unused. • Most memory allocators do not return memory to the OS. However this has not been a problem....
View Full Document

This note was uploaded on 01/30/2012 for the course CS 354 taught by Professor Staff during the Fall '08 term at Purdue.

Page1 / 7

Explicit Memory Management - • Sbrk(s increases the size...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online