22_2 - Dynamic Memory Allocation 1 Outline...

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

View Full Document Right Arrow Icon
1 Dynamic Memory Allocation
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Outline Implementation of a simple allocator Explicit Free List Segregated Free List Suggested reading: 10.9
Background image of page 2
3 Dynamic Memory Allocation Explicit vs. Implicit Memory Allocator Explicit:  application allocates and frees space  E.g.,  malloc  and  free  in C Implicit: application allocates, but does not free space E.g. garbage collection in Java, ML or Lisp
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Dynamic Memory Allocation Allocation In both cases the memory allocator provides an abstraction of  memory as a set of blocks Doles out free memory blocks to application
Background image of page 4
5 Malloc package #include <stdlib.h> void *malloc(size_t size) if successful: returns a pointer to a memory block of at least size bytes, aligned to 8-byte boundary. if size==0, returns NULL if unsuccessful: returns NULL void free(void *p) returns the block pointed at by p to pool of available memory p must come from a previous call to malloc,calloc or realloc.
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 sbrk() Function #include <unistd.h> void *sbrk(int incr) If successful It returns the old value of brk If unsuccessful It returns –1 It sets errno to ENOMEM If incr is zero It returns the current value incr can be a negative number
Background image of page 6
7 1 #include "csapp.h" 2 #define MAXN 15213 3 4 int array[MAXN]; 5 Why Dynamic Memory Allocation
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 000 taught by Professor Jing during the Fall '10 term at Fudan University.

Page1 / 23

22_2 - Dynamic Memory Allocation 1 Outline...

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

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