当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

复旦大学:《计算机原理 Computer System》课程PPT课件_Dynamic Memory Allocation(• Implementation of a simple allocator • Explicit Free List • Segregated Free List)

资源类别:文库,文档格式:PPT,文档页数:114,文件大小:635.5KB,团购合买
• Implementation of a simple allocator • Explicit Free List • Segregated Free List • Suggested reading
点击下载完整版文档(PPT)

Dynamic Memory Allocation

1 Dynamic Memory Allocation

Outline Implementation of a simple allocator Explicit Free List Segregated Free List 5 uggested reading:10.9,10.10,.10.110.12, 10.13 Segregate:隔离

2 Outline • Implementation of a simple allocator • Explicit Free List • Segregated Free List • Suggested reading: 10.9, 10.10, 10.11, 10.12, 10.13 Segregate:隔离

ynamic Memory Allocation P731 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

3 Dynamic Memory Allocation P731 • 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

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 Doles:发放

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 Doles: 发放

10.9. 1 The malloc and free Functions

5 10.9.1 The malloc and free Functions

Malloc package P731 ·# include 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

6 Malloc package P731 • #include • 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

sarko Function P732 ·# include void* sbrk(int incr) If successful It returns the old value of brk If unsuccessful · It returns-1 · It sets errno to nomen If incr is zero It returns the current value incr can be a negative number

7 sbrk() Function P732 • #include • 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

Assumptions Assumptions made in this lecture memory is word addressed (each word can hold a pointer) Free word Allocated block Free block (4 words) 3 words) Allocated word

8 • Assumptions made in this lecture – memory is word addressed (each word can hold a pointer) Allocated block (4 words) Free block (3 words) Free word Allocated word Assumptions

Allocation examples pl malloc(4) p2 malloc(5) 3=ma11oc(6) free(p2) p4 malloc(2) Figure 10.36 P733

9 p1 = malloc(4) p2 = malloc(5) p3 = malloc(6) free(p2) p4 = malloc(2) Allocation examples Figure 10.36 P733

10.9.2 Why Dynamic Memory Allocation

10 10.9.2 Why Dynamic Memory Allocation

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共114页,可试读30页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有