Memory management. Johan Montelius KTH

Size: px
Start display at page:

Download "Memory management. Johan Montelius KTH"

Transcription

1 Memory management Johan Montelius KTH / 22

2 C program # include <stdlib.h> int global = 42; int main ( int argc, char * argv []) { if( argc < 2) return -1; int n = atoi ( argv [1]); int on_stack [5] = {1,2,3,4,5}; int * on_heap = malloc ( sizeof ( int )*n); : } 2 / 22

3 The POSIX API The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. # include <stdlib.h> void * malloc ( size_t size ); void free ( void * ptr ); 3 / 22

4 The POSIX API The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. # include <stdlib.h> void * malloc ( size_t size ); void free ( void * ptr ); 3 / 22

5 The POSIX API # include <stdlib.h> void * malloc ( size_t size ); void free ( void * ptr ); The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). 3 / 22

6 The POSIX API # include <stdlib.h> void * malloc ( size_t size ); void free ( void * ptr ); The malloc() function allocates size bytes and returns a pointer to the allocated memory. The memory is not initialized. If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free(). The free() function frees the memory space pointed to by ptr, which must have been returned by a previous call to malloc(),.. : 3 / 22

7 The operating system Application layer Operating system 4 / 22

8 The operating system user process Application layer Operating system 4 / 22

9 The operating system user process code Application layer Operating system 4 / 22

10 The operating system user process code Application layer library Operating system kernel 4 / 22

11 The operating system user process code Application layer library Operating system Systems calls (trap to kernel space) kernel 4 / 22

12 The operating system user process code Application layer Operating system API (POSIX) library Operating system Systems calls (trap to kernel space) kernel 4 / 22

13 The operating system user process code Application layer Operating system API (POSIX) library Operating system Systems calls (trap to kernel space) kernel Library is often just a wrapper for the system call - sometimes more complex. 4 / 22

14 Linux system call brk() and sbrk() change the location of the program break, which defines the end of the process s data segment # include <unistd.h> int brk ( void * addr ); void * sbrk ( intptr_t incr ); 5 / 22

15 Linux system call # include <unistd.h> int brk ( void * addr ); void * sbrk ( intptr_t incr ); brk() and sbrk() change the location of the program break, which defines the end of the process s data segment brk() sets the end of the data segment to the value specified by addr 5 / 22

16 Linux system call # include <unistd.h> int brk ( void * addr ); void * sbrk ( intptr_t incr ); brk() and sbrk() change the location of the program break, which defines the end of the process s data segment brk() sets the end of the data segment to the value specified by addr sbrk() increments the program s data space by increment bytes. 5 / 22

17 Linux system call # include <unistd.h> int brk ( void * addr ); void * sbrk ( intptr_t incr ); brk() and sbrk() change the location of the program break, which defines the end of the process s data segment brk() sets the end of the data segment to the value specified by addr sbrk() increments the program s data space by increment bytes. Calling sbrk() with an increment of 0 can be used to find the current location of the program break. 5 / 22

18 User space program 6 / 22

19 User space program Library routines malloc() / free() 6 / 22

20 User space program Library routines malloc() / free() Kernel space sbrk() 6 / 22

21 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

22 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

23 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

24 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

25 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

26 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

27 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() 6 / 22

28 User space program char a[10] structs person {int age; char name[20]} Library routines malloc() / free() Kernel space sbrk() heap 6 / 22

29 Memory management If we would not have to reuse freed memory areas - management would be simple. 7 / 22

30 Memory management If we would not have to reuse freed memory areas - management would be simple. Calling sbrk() is costly i.e. better to do a few large allocations and then do several smaller malloc() operations. 7 / 22

31 Memory management If we would not have to reuse freed memory areas - management would be simple. Calling sbrk() is costly i.e. better to do a few large allocations and then do several smaller malloc() operations. Keep track of freed memory, to reuse it in following malloc(). 7 / 22

32 Memory management If we would not have to reuse freed memory areas - management would be simple. Calling sbrk() is costly i.e. better to do a few large allocations and then do several smaller malloc() operations. Keep track of freed memory, to reuse it in following malloc(). 7 / 22

33 A list of free blocks Assume each free block holds a header containing: the size and a pointer to the next block. typefdef struct node_t { int size; struct node_t *next; } 8 / 22

34 A list of free blocks Assume each free block holds a header containing: the size and a pointer to the next block. free typefdef struct node_t { int size; struct node_t *next; } 8 / 22

35 A list of free blocks Assume each free block holds a header containing: the size and a pointer to the next block. free typefdef struct node_t { int size; struct node_t *next; } 8 / 22

36 A list of free blocks Assume each free block holds a header containing: the size and a pointer to the next block. free typefdef struct node_t { int size; struct node_t *next; } 8 / 22

37 A list of free blocks Assume each free block holds a header containing: the size and a pointer to the next block. free typefdef struct node_t { int size; struct node_t *next; } 8 / 22

38 A list of free blocks Assume each free block holds a header containing: the size and a pointer to the next block. free typefdef struct node_t { int size; struct node_t *next; } 8 / 22

39 return a block How do we return a block? free typefdef struct header_t { int size; int magic; } 9 / 22

40 return a block How do we return a block? free free(this) typefdef struct header_t { int size; int magic; } 9 / 22

41 return a block How do we return a block? free free(this) typefdef struct header_t { int size; int magic; } 9 / 22

42 return a block How do we return a block? free typefdef struct header_t { int size; int magic; } 9 / 22

43 return a block How do we return a block? free typefdef struct header_t { int size; int magic; } 9 / 22

44 return a block How do we return a block? free typefdef struct header_t { int size; int magic; } What s the problem? 9 / 22

45 hidden information : char * buf = malloc ( 128); : 10 / 22

46 hidden information : char * buf = malloc ( 128); : 10 / 22

47 hidden information buf : char * buf = malloc ( 128); : 10 / 22

48 hidden information buf 128 : char * buf = malloc ( 128); : 10 / 22

49 hidden information buf 128 0x4af1e2 : char * buf = malloc ( 128); : 10 / 22

50 hidden information buf 128 0x4af1e2 : char * buf = malloc ( 128); : 10 / 22

51 hidden information buf 128 0x4af1e2 : char * buf = malloc ( 128); : 128 bytes 10 / 22

52 Coalescing - merging free blocks free When we return a block we need to merge it with adjacent free blocks - if any. 11 / 22

53 Coalescing - merging free blocks free free(this) When we return a block we need to merge it with adjacent free blocks - if any. 11 / 22

54 Coalescing - merging free blocks free free(this) When we return a block we need to merge it with adjacent free blocks - if any. 11 / 22

55 Coalescing - merging free blocks free When we return a block we need to merge it with adjacent free blocks - if any. 11 / 22

56 Coalescing - merging free blocks free When we return a block we need to merge it with adjacent free blocks - if any. 11 / 22

57 Coalescing - merging free blocks free When we return a block we need to merge it with adjacent free blocks - if any. 11 / 22

58 Malloc - find a suitable block and split it. free 12 / 22

59 Malloc - find a suitable block and split it. free 12 / 22

60 Malloc - find a suitable block and split it. free 12 / 22

61 Malloc - find a suitable block and split it. free 12 / 22

62 Malloc - find a suitable block and split it. free Which block shall we pick? 12 / 22

63 Free list strategies Best fit: the block that minimize the left over. 13 / 22

64 Free list strategies Best fit: the block that minimize the left over. Worst fit: the block that maximize the left over. 13 / 22

65 Free list strategies Best fit: the block that minimize the left over. Worst fit: the block that maximize the left over. First fit: pick the first one. 13 / 22

66 Free list strategies Best fit: the block that minimize the left over. Worst fit: the block that maximize the left over. First fit: pick the first one. You should know the pros and cons of these strategies. 13 / 22

67 Segregated lists Idéa - keep separate lists of blocks of different size. 14 / 22

68 Segregated lists Idéa - keep separate lists of blocks of different size. Assume we keep lists for blocks of: 8, 16, 32, bytes. 14 / 22

69 Segregated lists Idéa - keep separate lists of blocks of different size. Assume we keep lists for blocks of: 8, 16, 32, bytes. Easy to serve and return blocks of given size. 14 / 22

70 Segregated lists Idéa - keep separate lists of blocks of different size. Assume we keep lists for blocks of: 8, 16, 32, bytes. Easy to serve and return blocks of given size. What should we do if we are asked for block of size 24? 14 / 22

71 Segregated lists Idéa - keep separate lists of blocks of different size. Assume we keep lists for blocks of: 8, 16, 32, bytes. Easy to serve and return blocks of given size. What should we do if we are asked for block of size 24? What sizes should we choose, what needs to be considered? 14 / 22

72 Segregated lists Idéa - keep separate lists of blocks of different size. Assume we keep lists for blocks of: 8, 16, 32, bytes. Easy to serve and return blocks of given size. What should we do if we are asked for block of size 24? What sizes should we choose, what needs to be considered? We can build our own allocator that is optimized for a given application. 14 / 22

73 malloc in GNU/Linux The C standard library glibc used in most GNU/Linux distributions use a memory allocator called ptmalloc3 (pthread malloc). 15 / 22

74 malloc in GNU/Linux The C standard library glibc used in most GNU/Linux distributions use a memory allocator called ptmalloc3 (pthread malloc). Multithreaded, each thread has a separate heap. 15 / 22

75 malloc in GNU/Linux The C standard library glibc used in most GNU/Linux distributions use a memory allocator called ptmalloc3 (pthread malloc). Multithreaded, each thread has a separate heap. Uses multiple bins (free lists) to keep chunks of different size. 15 / 22

76 malloc in GNU/Linux The C standard library glibc used in most GNU/Linux distributions use a memory allocator called ptmalloc3 (pthread malloc). Multithreaded, each thread has a separate heap. Uses multiple bins (free lists) to keep chunks of different size. Will coalesce adjacent chunks. 15 / 22

77 Buddy Allocation If we should allow blocks to be divided then we should also provide efficient coalescing. 16 / 22

78 Buddy Allocation If we should allow blocks to be divided then we should also provide efficient coalescing. Assume total memory 128Kibyte, smallest allocated frame 4Kibyte 4 16 / 22

79 Buddy Allocation If we should allow blocks to be divided then we should also provide efficient coalescing. Assume total memory 128Kibyte, smallest allocated frame 4Kibyte / 22

80 Buddy Allocation If we should allow blocks to be divided then we should also provide efficient coalescing. Assume total memory 128Kibyte, smallest allocated frame 4Kibyte / 22

81 Buddy Allocation If we should allow blocks to be divided then we should also provide efficient coalescing. Assume total memory 128Kibyte, smallest allocated frame 4Kibyte / 22

82 Buddy Allocation If we should allow blocks to be divided then we should also provide efficient coalescing. Assume total memory 128Kibyte, smallest allocated frame 4Kibyte / 22

83 Find your buddy Assume we number our 32 frames from 0b00000 to 0b Who s the buddy of: 17 / 22

84 Find your buddy Assume we number our 32 frames from 0b00000 to 0b Who s the buddy of: 4K at 0b / 22

85 Find your buddy Assume we number our 32 frames from 0b00000 to 0b Who s the buddy of: 4K at 0b K at 0b / 22

86 Find your buddy Assume we number our 32 frames from 0b00000 to 0b Who s the buddy of: 4K at 0b K at 0b K at 0b / 22

87 Buddy pros and cons Pros: 18 / 22

88 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. 18 / 22

89 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. Coalescing efficient, O(lg(n)) 18 / 22

90 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. Coalescing efficient, O(lg(n)) Handles external fragmentation well. 18 / 22

91 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. Coalescing efficient, O(lg(n)) Handles external fragmentation well. Cons: 18 / 22

92 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. Coalescing efficient, O(lg(n)) Handles external fragmentation well. Cons: Internal fragmentation - if we need a frame of 9 blocks we get 16! 18 / 22

93 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. Coalescing efficient, O(lg(n)) Handles external fragmentation well. Cons: Internal fragmentation - if we need a frame of 9 blocks we get 16! 18 / 22

94 Buddy pros and cons Pros: Efficient allocation and deallocations of frames. Coalescing efficient, O(lg(n)) Handles external fragmentation well. Cons: Internal fragmentation - if we need a frame of 9 blocks we get 16! Linux uses Buddy allocations when managing physical memory - check /proc/buddyinfo. 18 / 22

95 mmap - memory map # include <sys / mman.h> mmap() creates a new mapping in the virtual address space of the calling process. void * mmap ( void *addr, size_ t length, int prot, int flags, int fd, off_ t offset ); 19 / 22

96 mmap - memory map # include <sys / mman.h> void * mmap ( void *addr, size_ t length, int prot, int flags, int fd, off_ t offset ); mmap() creates a new mapping in the virtual address space of the calling process. The length argument specifies the length of the mapping. 19 / 22

97 mmap - memory map # include <sys / mman.h> void * mmap ( void *addr, size_ t length, int prot, int flags, int fd, off_ t offset ); mmap() creates a new mapping in the virtual address space of the calling process. The length argument specifies the length of the mapping. If addr is NULL, then the kernel chooses the address at which to create the mapping; 19 / 22

98 mmap - memory map # include <sys / mman.h> void * mmap ( void *addr, size_ t length, int prot, int flags, int fd, off_ t offset ); mmap() creates a new mapping in the virtual address space of the calling process. The length argument specifies the length of the mapping. If addr is NULL, then the kernel chooses the address at which to create the mapping; The prot argument describes the desired memory protection of the mapping.. 19 / 22

99 mmap - memory map # include <sys / mman.h> void * mmap ( void *addr, size_ t length, int prot, int flags, int fd, off_ t offset ); mmap() creates a new mapping in the virtual address space of the calling process. The length argument specifies the length of the mapping. If addr is NULL, then the kernel chooses the address at which to create the mapping; The prot argument describes the desired memory protection of the mapping.. flags, fd and offset for mapping of file in memory 19 / 22

100 mmap - memory map # include <sys / mman.h> void * mmap ( void *addr, size_ t length, int prot, int flags, int fd, off_ t offset ); mmap() creates a new mapping in the virtual address space of the calling process. The length argument specifies the length of the mapping. If addr is NULL, then the kernel chooses the address at which to create the mapping; The prot argument describes the desired memory protection of the mapping.. flags, fd and offset for mapping of file in memory Originally from 4.2BSD, default in OSX where mallc() uses mmap() to allocate memory. 19 / 22

101 sbrk() vs mmap() brk() and sbrk() easy to extend the process heap 20 / 22

102 sbrk() vs mmap() brk() and sbrk() easy to extend the process heap not easy to hand back allocated memory 20 / 22

103 sbrk() vs mmap() brk() and sbrk() easy to extend the process heap not easy to hand back allocated memory only one heap 20 / 22

104 sbrk() vs mmap() brk() and sbrk() easy to extend the process heap not easy to hand back allocated memory only one heap not part of POSIX mmap() POSIX standard 20 / 22

105 sbrk() vs mmap() brk() and sbrk() easy to extend the process heap not easy to hand back allocated memory only one heap not part of POSIX mmap() POSIX standard easy to allocate several large areas 20 / 22

106 sbrk() vs mmap() brk() and sbrk() easy to extend the process heap not easy to hand back allocated memory only one heap not part of POSIX mmap() POSIX standard easy to allocate several large areas easy to hand back allocated memory ability to map a file in memory 20 / 22

107 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. 21 / 22

108 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. 21 / 22

109 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. 21 / 22

110 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. Cons: hard to find bugs when you don t do it right. 21 / 22

111 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. Cons: hard to find bugs when you don t do it right. Implicit memory management: memory is freed by the system. 21 / 22

112 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. Cons: hard to find bugs when you don t do it right. Implicit memory management: memory is freed by the system. Managed by the runtime system i.e. a garbage collector (Java, Erlang, Python,..) or by the compiler (Mercury, Rust...). 21 / 22

113 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. Cons: hard to find bugs when you don t do it right. Implicit memory management: memory is freed by the system. Managed by the runtime system i.e. a garbage collector (Java, Erlang, Python,..) or by the compiler (Mercury, Rust...). Pros: much simpler and/or safer. 21 / 22

114 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. Cons: hard to find bugs when you don t do it right. Implicit memory management: memory is freed by the system. Managed by the runtime system i.e. a garbage collector (Java, Erlang, Python,..) or by the compiler (Mercury, Rust...). Pros: much simpler and/or safer. Cons: could result in runtime overhead and/or lack of control. 21 / 22

115 Programmers point of view Explicit memory management: the programmer needs to explicitly free objects. Used in C, C++ and most system level programming languages. Pros: efficient usage of memory. Cons: hard to find bugs when you don t do it right. Implicit memory management: memory is freed by the system. Managed by the runtime system i.e. a garbage collector (Java, Erlang, Python,..) or by the compiler (Mercury, Rust...). Pros: much simpler and/or safer. Cons: could result in runtime overhead and/or lack of control. 21 / 22

116 Summary user process API: malloc() and free() 22 / 22

117 Summary user process API: malloc() and free() system calls: sbrk() or mmap() 22 / 22

118 Summary user process API: malloc() and free() system calls: sbrk() or mmap() how to find suitable memory block. 22 / 22

119 Summary user process API: malloc() and free() system calls: sbrk() or mmap() how to find suitable memory block. how to free memory blocks for efficient reuse 22 / 22

120 Summary user process API: malloc() and free() system calls: sbrk() or mmap() how to find suitable memory block. how to free memory blocks for efficient reuse coalescing smaller blocks 22 / 22

Operating System Labs. Yuanbin Wu

Operating System Labs. Yuanbin Wu Operating System Labs Yuanbin Wu CS@ECNU Operating System Labs Project 2 Due 21:00, Oct. 24 Project 3 Group of 3 If you can not find a partner, drop us an email You now have 3 late days, but start early!

More information

Princeton University Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management

Princeton University Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management Princeton University Computer Science 217: Introduction to Programming Systems Dynamic Memory Management 1 Goals of this Lecture Help you learn about: The need for dynamic* memory mgmt (DMM) Implementing

More information

Princeton University. Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management

Princeton University. Computer Science 217: Introduction to Programming Systems. Dynamic Memory Management Princeton University Computer Science 217: Introduction to Programming Systems Dynamic Memory Management 1 Agenda The need for DMM DMM using the heap section DMMgr 1: Minimal implementation DMMgr 2: Pad

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

My malloc: mylloc and mhysa. Johan Montelius HT2016

My malloc: mylloc and mhysa. Johan Montelius HT2016 1 Introduction My malloc: mylloc and mhysa Johan Montelius HT2016 So this is an experiment where we will implement our own malloc. We will not implement the world s fastest allocator, but it will work

More information

10.1. CS356 Unit 10. Memory Allocation & Heap Management

10.1. CS356 Unit 10. Memory Allocation & Heap Management 10.1 CS356 Unit 10 Memory Allocation & Heap Management 10.2 BASIC OS CONCEPTS & TERMINOLOGY 10.3 User vs. Kernel Mode Kernel mode is a special mode of the processor for executing trusted (OS) code Certain

More information

ECE 598 Advanced Operating Systems Lecture 10

ECE 598 Advanced Operating Systems Lecture 10 ECE 598 Advanced Operating Systems Lecture 10 Vince Weaver http://www.eece.maine.edu/~vweaver vincent.weaver@maine.edu 17 February 2015 Announcements Homework #1 and #2 grades, HW#3 Coming soon 1 Various

More information

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics

CSCI-UA /2. Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics Slides adapted (and slightly modified) from: Clark Barrett Jinyang Li Randy Bryant Dave O Hallaron CSCI-UA.0201-001/2 Computer Systems Organization Lecture 19: Dynamic Memory Allocation: Basics Mohamed

More information

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. To do. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory Management To do q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory management Ideal memory for a programmer large, fast, nonvolatile and cheap not

More information

Dynamic Memory Management! Goals of this Lecture!

Dynamic Memory Management! Goals of this Lecture! Dynamic Memory Management!!! 1 Goals of this Lecture! Help you learn about:! Dynamic memory management techniques! Garbage collection by the run-time system (Java)! Manual deallocation by the programmer

More information

ECE 598 Advanced Operating Systems Lecture 12

ECE 598 Advanced Operating Systems Lecture 12 ECE 598 Advanced Operating Systems Lecture 12 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 1 March 2018 Announcements Next homework will be due after break. Midterm next Thursday

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation CS61, Lecture 10 Prof. Stephen Chong October 4, 2011 Announcements 1/2 Assignment 4: Malloc Will be released today May work in groups of one or two Please go to website and enter

More information

Dynamic Memory Allocation I Nov 5, 2002

Dynamic Memory Allocation I Nov 5, 2002 15-213 The course that gives CMU its Zip! Dynamic Memory Allocation I Nov 5, 2002 Topics Simple explicit allocators Data structures Mechanisms Policies class21.ppt Harsh Reality Memory is not unbounded

More information

Dynamic Memory Management

Dynamic Memory Management Dynamic Memory Management 1 Goals of this Lecture Help you learn about: Dynamic memory management techniques Garbage collection by the run-time system (Java) Manual deallocation by the programmer (C, C++)

More information

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory

Memory Management. q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory Management q Basic memory management q Swapping q Kernel memory allocation q Next Time: Virtual memory Memory management Ideal memory for a programmer large, fast, nonvolatile and cheap not an option

More information

Dynamic Memory Allocation I

Dynamic Memory Allocation I Dynamic Memory Allocation I William J. Taffe Plymouth State University Using the Slides of Randall E. Bryant Carnegie Mellon University Topics Simple explicit allocators Data structures Mechanisms Policies

More information

Dynamic Memory Allocation. Zhaoguo Wang

Dynamic Memory Allocation. Zhaoguo Wang Dynamic Memory Allocation Zhaoguo Wang Why dynamic memory allocation? Do not know the size until the program runs (at runtime). #define MAXN 15213 int array[maxn]; int main(void) { int i, n; scanf("%d",

More information

Heap Management portion of the store lives indefinitely until the program explicitly deletes it C++ and Java new Such objects are stored on a heap

Heap Management portion of the store lives indefinitely until the program explicitly deletes it C++ and Java new Such objects are stored on a heap Heap Management The heap is the portion of the store that is used for data that lives indefinitely, or until the program explicitly deletes it. While local variables typically become inaccessible when

More information

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th

Introduction to Computer Systems /18 243, fall th Lecture, Oct. 22 th Introduction to Computer Systems 15 213/18 243, fall 2009 16 th Lecture, Oct. 22 th Instructors: Gregory Kesden and Markus Püschel Today Dynamic memory allocation Process Memory Image %esp kernel virtual

More information

Lectures 13 & 14. memory management

Lectures 13 & 14. memory management Lectures 13 & 14 Linked lists and memory management Courtesy of Prof. Garcia (UCB) CS61C L05 Introduction to C (pt 3) (1) Review Pointers and arrays are virtually same C knows how to increment pointers

More information

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1 Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Memory allocation within a process What happens when you declare a variable? Allocating a page for every variable wouldn t be efficient

More information

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty

Process s Address Space. Dynamic Memory. Backing the Heap. Dynamic memory allocation 3/29/2013. When a process starts the heap is empty /9/01 Process s Address Space Dynamic Memory 0x7fffffff Stack Data (Heap) Data (Heap) 0 Text (Code) Backing the Heap When a process starts the heap is empty The process is responsible for requesting memory

More information

Dynamic Memory Allocation. Gerson Robboy Portland State University. class20.ppt

Dynamic Memory Allocation. Gerson Robboy Portland State University. class20.ppt Dynamic Memory Allocation Gerson Robboy Portland State University class20.ppt Harsh Reality Memory is not unbounded It must be allocated and managed Many applications are memory dominated Especially those

More information

Memory Allocation I. CSE 351 Autumn Instructor: Justin Hsia

Memory Allocation I. CSE 351 Autumn Instructor: Justin Hsia Memory Allocation I CSE 351 Autumn 2017 Instructor: Justin Hsia Teaching Assistants: Lucas Wotton Michael Zhang Parker DeWilde Ryan Wong Sam Gehman Sam Wolfson Savanna Yee Vinny Palaniappan Administrivia

More information

Dynamic Memory Allocation. Basic Concepts. Computer Organization 4/3/2012. CSC252 - Spring The malloc Package. Kai Shen

Dynamic Memory Allocation. Basic Concepts. Computer Organization 4/3/2012. CSC252 - Spring The malloc Package. Kai Shen Dynamic Memory Allocation: Basic Concepts Kai Shen Dynamic Memory Allocation Programmers use dynamic memory allocators (such as malloc) to acquire memory at run time. For data structures whose size is

More information

Review! Lecture 5 C Memory Management !

Review! Lecture 5 C Memory Management ! CS61C L05 C Memory Management (1)! inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management 2010-06-28!!! Instructor Paul Pearce! Symmetric multiprocessor! MIPS support for

More information

In Java we have the keyword null, which is the value of an uninitialized reference type

In Java we have the keyword null, which is the value of an uninitialized reference type + More on Pointers + Null pointers In Java we have the keyword null, which is the value of an uninitialized reference type In C we sometimes use NULL, but its just a macro for the integer 0 Pointers are

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 5 C Memory Management 2010-06-28!!! Instructor Paul Pearce! Symmetric multiprocessor! MIPS support for Android MIPS Technologies (founded

More information

Dynamic Memory Allocation: Basic Concepts

Dynamic Memory Allocation: Basic Concepts Dynamic Memory Allocation: Basic Concepts 15-213: Introduction to Computer Systems 19 th Lecture, March 30, 2017 Instructor: Franz Franchetti & Seth Copen Goldstein 1 Today Basic concepts Implicit free

More information

COSC Software Engineering. Lectures 14 and 15: The Heap and Dynamic Memory Allocation

COSC Software Engineering. Lectures 14 and 15: The Heap and Dynamic Memory Allocation COSC345 2013 Software Engineering Lectures 14 and 15: The Heap and Dynamic Memory Allocation Outline Revision The programmer s view of memory Simple array-based memory allocation C memory allocation routines

More information

Secure Software Programming and Vulnerability Analysis

Secure Software Programming and Vulnerability Analysis Secure Software Programming and Vulnerability Analysis Christopher Kruegel chris@auto.tuwien.ac.at http://www.auto.tuwien.ac.at/~chris Heap Buffer Overflows and Format String Vulnerabilities Secure Software

More information

CS 33. Storage Allocation. CS33 Intro to Computer Systems XXVII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Storage Allocation. CS33 Intro to Computer Systems XXVII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Storage Allocation CS33 Intro to Computer Systems XXVII 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. The Unix Address Space stack dynamic bss program break data text CS33 Intro to Computer

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c/su06 CS61C : Machine Structures Lecture #6: Memory Management CS 61C L06 Memory Management (1) 2006-07-05 Andy Carle Memory Management (1/2) Variable declaration allocates

More information

Processes, Address Spaces, and Memory Management. CS449 Spring 2016

Processes, Address Spaces, and Memory Management. CS449 Spring 2016 Processes, Address Spaces, and Memory Management CS449 Spring 2016 Process A running program and its associated data Process s Address Space 0x7fffffff Stack Data (Heap) Data (Heap) Globals Text (Code)

More information

Class Information ANNOUCEMENTS

Class Information ANNOUCEMENTS Class Information ANNOUCEMENTS Third homework due TODAY at 11:59pm. Extension? First project has been posted, due Monday October 23, 11:59pm. Midterm exam: Friday, October 27, in class. Don t forget to

More information

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package Today Dynamic Memory Allocation: Basic Concepts Basic concepts Performance concerns Approach 1: implicit free lists CSci 01: Machine Architecture and Organization October 17th-nd, 018 Your instructor:

More information

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2

A.Arpaci-Dusseau. Mapping from logical address space to physical address space. CS 537:Operating Systems lecture12.fm.2 UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department CS 537 A. Arpaci-Dusseau Intro to Operating Systems Spring 2000 Dynamic Memory Allocation Questions answered in these notes When is a stack

More information

Dynamic Data Structures. CSCI 112: Programming in C

Dynamic Data Structures. CSCI 112: Programming in C Dynamic Data Structures CSCI 112: Programming in C 1 It s all about flexibility In the programs we ve made so far, the compiler knows at compile time exactly how much memory to allocate for each variable

More information

Operating systems. Lecture 9

Operating systems. Lecture 9 Operating systems. Lecture 9 Michał Goliński 2018-11-27 Introduction Recall Reading and writing wiles in the C/C++ standard libraries System calls managing processes (fork, exec etc.) Plan for today fork

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture #4 C Memory Management 2007-06-28 Scott Beamer, Instructor iphone Comes out Tomorrow CS61C L4 C Memory Management (1) www.apple.com/iphone

More information

Memory Management. CS449 Fall 2017

Memory Management. CS449 Fall 2017 Memory Management CS449 Fall 2017 Life9mes Life9me: 9me from which a par9cular memory loca9on is allocated un9l it is deallocated Three types of life9mes Automa9c (within a scope) Sta9c (dura9on of program)

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation Computer Systems Organization (Spring 2017) CSCI-UA 201, Section 3 Instructor: Joanna Klukowska Slides adapted from Randal E. Bryant and David R. O Hallaron (CMU) Mohamed Zahran

More information

Dynamic Memory Allocation

Dynamic Memory Allocation 1 Dynamic Memory Allocation Anne Bracy CS 3410 Computer Science Cornell University Note: these slides derive from those by Markus Püschel at CMU 2 Recommended Approach while (TRUE) { code a little; test

More information

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture:

Motivation for Dynamic Memory. Dynamic Memory Allocation. Stack Organization. Stack Discussion. Questions answered in this lecture: CS 537 Introduction to Operating Systems UNIVERSITY of WISCONSIN-MADISON Computer Sciences Department Dynamic Memory Allocation Questions answered in this lecture: When is a stack appropriate? When is

More information

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package

Today. Dynamic Memory Allocation: Basic Concepts. Dynamic Memory Allocation. Dynamic Memory Allocation. malloc Example. The malloc Package Today Dynamic Memory Allocation: Basic Concepts Basic concepts Performance concerns Approach 1: implicit free lists CSci 01: Machine Architecture and Organization Lecture #9, April th, 016 Your instructor:

More information

What is concurrency? Concurrency. What is parallelism? concurrency vs parallelism. Concurrency: (the illusion of) happening at the same time.

What is concurrency? Concurrency. What is parallelism? concurrency vs parallelism. Concurrency: (the illusion of) happening at the same time. What is concurrency? Concurrency Johan Montelius KTH 2017 Concurrency: (the illusion of) happening at the same time. A property of the programing model. Why would we want to do things concurrently? What

More information

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia

Memory Allocation II. CSE 351 Autumn Instructor: Justin Hsia Memory Allocation II CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun

More information

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14

SYSTEM CALL IMPLEMENTATION. CS124 Operating Systems Fall , Lecture 14 SYSTEM CALL IMPLEMENTATION CS124 Operating Systems Fall 2017-2018, Lecture 14 2 User Processes and System Calls Previously stated that user applications interact with the kernel via system calls Typically

More information

Concurrency. Johan Montelius KTH

Concurrency. Johan Montelius KTH Concurrency Johan Montelius KTH 2017 1 / 32 What is concurrency? 2 / 32 What is concurrency? Concurrency: (the illusion of) happening at the same time. 2 / 32 What is concurrency? Concurrency: (the illusion

More information

Run-time Environments - 3

Run-time Environments - 3 Run-time Environments - 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time

More information

Lecture 8 Dynamic Memory Allocation

Lecture 8 Dynamic Memory Allocation Lecture 8 Dynamic Memory Allocation CS240 1 Memory Computer programs manipulate an abstraction of the computer s memory subsystem Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable

More information

Recitation #11 Malloc Lab. November 7th, 2017

Recitation #11 Malloc Lab. November 7th, 2017 18-600 Recitation #11 Malloc Lab November 7th, 2017 1 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than 32 bit Encourages

More information

Memory Allocation I. CSE 351 Autumn Instructor: Justin Hsia

Memory Allocation I. CSE 351 Autumn Instructor: Justin Hsia Memory Allocation I CSE 351 Autumn 2016 Instructor: Justin Hsia Teaching Assistants: Chris Ma Hunter Zahn John Kaltenbach Kevin Bi Sachin Mehta Suraj Bhat Thomas Neuman Waylon Huang Xi Liu Yufang Sun Adapted

More information

Dynamic Memory Allocation: Basic Concepts

Dynamic Memory Allocation: Basic Concepts Dynamic Memory Allocation: Basic Concepts CSE 238/2038/2138: Systems Programming Instructor: Fatma CORUT ERGİN Slides adapted from Bryant & O Hallaron s slides 1 Today Basic concepts Implicit free lists

More information

ANITA S SUPER AWESOME RECITATION SLIDES

ANITA S SUPER AWESOME RECITATION SLIDES ANITA S SUPER AWESOME RECITATION SLIDES 15/18-213: Introduction to Computer Systems Dynamic Memory Allocation Anita Zhang, Section M UPDATES Cache Lab style points released Don t fret too much Shell Lab

More information

Understanding Pointers

Understanding Pointers Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer

More information

Optimizing Dynamic Memory Management

Optimizing Dynamic Memory Management Optimizing Dynamic Memory Management 1 Goals of this Lecture Help you learn about: Details of K&R heap mgr Heap mgr optimizations related to Assignment #5 Faster free() via doubly-linked list, redundant

More information

COSC345 Software Engineering. The Heap And Dynamic Memory Allocation

COSC345 Software Engineering. The Heap And Dynamic Memory Allocation COSC345 Software Engineering The Heap And Dynamic Memory Allocation Outline Revision The programmer s view of memory Simple array-based memory allocation C memory allocation routines Virtual memory Swapping

More information

CS Computer Systems. Lecture 8: Free Memory Management

CS Computer Systems. Lecture 8: Free Memory Management CS 5600 Computer Systems Lecture 8: Free Memory Management Recap of Last Week Last week focused on virtual memory Gives each process the illusion of vast, empty memory Offers protection and isolation 31

More information

DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX

DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX DYNAMIC MEMORY ALLOCATION ON REAL-TIME LINUX Jianping Shen Institut Dr. Foerster GmbH und Co. KG In Laisen 70, 72766, Reutlingen, Germany shen.jianping@foerstergroup.de Michael Hamal Institut Dr. Foerster

More information

14. Memory API. Operating System: Three Easy Pieces

14. Memory API. Operating System: Three Easy Pieces 14. Memory API Oerating System: Three Easy Pieces 1 Memory API: malloc() #include void* malloc(size_t size) Allocate a memory region on the hea. w Argument size_t size : size of the memory block(in

More information

mmalloc The GNU memory-mapped malloc package Fred Fish Cygnus Support Mike Haertel Free Software Foundation

mmalloc The GNU memory-mapped malloc package Fred Fish Cygnus Support Mike Haertel Free Software Foundation mmalloc The GNU memory-mapped malloc package Fred Fish Cygnus Support Mike Haertel Free Software Foundation Cygnus Support fnf@cygnus.com MMALLOC, the GNU memory-mapped malloc package, Revision: 1.4 TEXinfo

More information

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016 CS 31: Intro to Systems Pointers and Memory Martin Gagne Swarthmore College February 16, 2016 So we declared a pointer How do we make it point to something? 1. Assign it the address of an existing variable

More information

malloc() is often used to allocate chunk of memory dynamically from the heap region. Each chunk contains a header and free space (the buffer in which

malloc() is often used to allocate chunk of memory dynamically from the heap region. Each chunk contains a header and free space (the buffer in which Heap Overflow malloc() is often used to allocate chunk of memory dynamically from the heap region. Each chunk contains a header and free space (the buffer in which data are placed). The header contains

More information

Run-time Environments -Part 3

Run-time Environments -Part 3 Run-time Environments -Part 3 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Compiler Design Outline of the Lecture Part 3 What is run-time support?

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 7 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 7 LAST TIME Dynamic memory allocation and the heap: A run-time facility that satisfies multiple needs: Programs can use widely varying, possibly

More information

Inside ptmalloc2. Peng Xu Sep 14, 2013

Inside ptmalloc2. Peng Xu Sep 14, 2013 Inside ptmalloc2 Peng Xu peng.p.xu@ericsson.com Sep 14, 2013 Part I basic concept and data structure Memory Translation process memory layout kernel space command line and environment variables stack heap

More information

HW 3: Malloc CS 162. Due: Monday, March 28, 2016

HW 3: Malloc CS 162. Due: Monday, March 28, 2016 CS 162 Due: Monday, March 28, 2016 1 Introduction Your task in this assignment is to implement your own memory allocator from scratch. This will expose you to POSIX interfaces, force you to reason about

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru Department of Electronics and Communication Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru Department of Electronics and Communication Engineering PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -560100 Department of Electronics and Communication Engineering Faculty: Richa Sharma Subject: Operating System SCHEME & SOLUTION

More information

Dynamic Memory Management

Dynamic Memory Management Dynamic Memory Management Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Lecture Dynamic memory management o Garbage collection by the run-time system (Java) o Manual deallocation

More information

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010

PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles. October 1, 2010 PROJECT 2 - MEMORY ALLOCATOR Computer Systems Principles Emery Berger Mark Corner October 1, 2010 1 Overview The purpose of this project is to acquaint you with how memory allocators provide virtual memory

More information

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare.

6.172 Performance Engineering of Software Systems Spring Lecture 9. P after. Figure 1: A diagram of the stack (Image by MIT OpenCourseWare. 6.172 Performance Engineering of Software Systems Spring 2009 Lecture 9 MIT OpenCourseWare Dynamic Storage Allocation Stack allocation: LIFO (last-in-first-out) Array and pointer A used unused P before

More information

Dynamic Storage Allocation

Dynamic Storage Allocation 6.172 Performance Engineering of Software Systems LECTURE 10 Dynamic Storage Allocation Charles E. Leiserson October 12, 2010 2010 Charles E. Leiserson 1 Stack Allocation Array and pointer A un Allocate

More information

Programming Languages

Programming Languages Programming Languages Tevfik Koşar Lecture - VIII February 9 th, 2006 1 Roadmap Allocation techniques Static Allocation Stack-based Allocation Heap-based Allocation Scope Rules Static Scopes Dynamic Scopes

More information

Foundations of Computer Systems

Foundations of Computer Systems 18-600 Foundations of Computer Systems Lecture 16: Dynamic Memory Allocation October 23, 2017 18-600 SE PL OS CA Required Reading Assignment: Chapter 9 of CS:APP (3 rd edition) by Randy Bryant & Dave O

More information

Dynamic Memory Allocation: Advanced Concepts

Dynamic Memory Allocation: Advanced Concepts Dynamic Memory Allocation: Advanced Concepts Keeping Track of Free Blocks Method 1: Implicit list using length links all blocks 5 4 6 Method : Explicit list among the free blocks using pointers 5 4 6 Kai

More information

Dynamic Memory Allocation

Dynamic Memory Allocation Dynamic Memory Allocation CS61, Lecture 11 Prof. Stephen Chong October 6, 2011 Announcements 1/2 Reminder: No section on Monday Monday sections have been rescheduled See website for details Please attend

More information

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers Introduction to C Geared toward programmers Robert Escriva Slide heritage: Alin Dobra Niranjan Nagarajan Owen Arden Cornell CS 4411, August 30, 2010 1 Why C? 2 A Quick Example 3 Programmer s Responsibilities

More information

Memory Management. CSC215 Lecture

Memory Management. CSC215 Lecture Memory Management CSC215 Lecture Outline Static vs Dynamic Allocation Dynamic allocation functions malloc, realloc, calloc, free Implementation Common errors Static Allocation Allocation of memory at compile-time

More information

CSE 333 SECTION 3. POSIX I/O Functions

CSE 333 SECTION 3. POSIX I/O Functions CSE 333 SECTION 3 POSIX I/O Functions Administrivia Questions (?) HW1 Due Tonight Exercise 7 due Monday (out later today) POSIX Portable Operating System Interface Family of standards specified by the

More information

Memory (Stack and Heap)

Memory (Stack and Heap) Memory (Stack and Heap) Praktikum C-Programmierung Nathanael Hübbe, Eugen Betke, Michael Kuhn, Jakob Lüttgau, Jannek Squar Wissenschaftliches Rechnen Fachbereich Informatik Universität Hamburg 2018-12-03

More information

CS 11 C track: lecture 5

CS 11 C track: lecture 5 CS 11 C track: lecture 5 Last week: pointers This week: Pointer arithmetic Arrays and pointers Dynamic memory allocation The stack and the heap Pointers (from last week) Address: location where data stored

More information

Base Component. Chapter 1. *Memory Management. Memory management Errors Exception Handling Messages Debug code Options Basic data types Multithreading

Base Component. Chapter 1. *Memory Management. Memory management Errors Exception Handling Messages Debug code Options Basic data types Multithreading Chapter 1. Base Component Component:, *Mathematics, *Error Handling, *Debugging The Base Component (BASE), in the base directory, contains the code for low-level common functionality that is used by all

More information

Recitation #12 Malloc Lab - Part 2. November 14th, 2017

Recitation #12 Malloc Lab - Part 2. November 14th, 2017 18-600 Recitation #12 Malloc Lab - Part 2 November 14th, 2017 1 2 REMINDER Malloc Lab checkpoint is due on 11/17 This is Friday (instead of the usual Thursday deadline) No late days available Final submission

More information

CA341 - Comparative Programming Languages

CA341 - Comparative Programming Languages CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data

More information

CS C Primer. Tyler Szepesi. January 16, 2013

CS C Primer. Tyler Szepesi. January 16, 2013 January 16, 2013 Topics 1 Why C? 2 Data Types 3 Memory 4 Files 5 Endianness 6 Resources Why C? C is exteremely flexible and gives control to the programmer Allows users to break rigid rules, which are

More information

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) !

! What is main memory? ! What is static and dynamic allocation? ! What is segmentation? Maria Hybinette, UGA. High Address (0x7fffffff) ! Memory Questions? CSCI [4 6]730 Operating Systems Main Memory! What is main memory?! How does multiple processes share memory space?» Key is how do they refer to memory addresses?! What is static and dynamic

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 More Memory Management CS 61C L07 More Memory Management (1) 2004-09-15 Lecturer PSOE Dan Garcia www.cs.berkeley.edu/~ddgarcia Star Wars

More information

CS61C : Machine Structures

CS61C : Machine Structures inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 7 C Memory Management 2007-02-06 Hello to Said S. from Columbus, OH CS61C L07 More Memory Management (1) Lecturer SOE Dan Garcia www.cs.berkeley.edu/~ddgarcia

More information

CS 241 Honors Memory

CS 241 Honors Memory CS 241 Honors Memory Ben Kurtovic Atul Sandur Bhuvan Venkatesh Brian Zhou Kevin Hong University of Illinois Urbana Champaign February 20, 2018 CS 241 Course Staff (UIUC) Memory February 20, 2018 1 / 35

More information

Memory Management william stallings, maurizio pizzonia - sistemi operativi

Memory Management william stallings, maurizio pizzonia - sistemi operativi Memory Management 1 summary goals and requirements techniques that do not involve virtual memory 2 memory management tracking used and free memory primitives allocation of a certain amount of memory de-allocation

More information

Dynamic Memory Alloca/on: Basic Concepts

Dynamic Memory Alloca/on: Basic Concepts Dynamic Memory Alloca/on: Basic Concepts 15-213 / 18-213: Introduc2on to Computer Systems 18 th Lecture, March. 26, 2013 Instructors: Anthony Rowe, Seth Goldstein, and Gregory Kesden 1 Today Basic concepts

More information

Requirements, Partitioning, paging, and segmentation

Requirements, Partitioning, paging, and segmentation Requirements, Partitioning, paging, and segmentation Main Memory: The Big Picture kernel memory proc struct kernel stack/u area Stack kernel stack/u area Stack kernel stack/u area Stack Data Text (shared)

More information

Memory Allocation III CSE 351 Spring (original source unknown)

Memory Allocation III CSE 351 Spring (original source unknown) Memory Allocation III CSE 351 Spring 2018 (original source unknown) Keeping Track of Free Blocks = 4-byte box (free) = 4-byte box (allocated) 1) Implicit free list using length links all blocks using math

More information

Engine Support System. asyrani.com

Engine Support System. asyrani.com Engine Support System asyrani.com A game engine is a complex piece of software consisting of many interacting subsystems. When the engine first starts up, each subsystem must be configured and initialized

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Inter-process Communication (IPC) Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Recall Process vs. Thread A process is

More information

CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: November 16, 11:30 PM

CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: November 16, 11:30 PM CS 322 Operating Systems Programming Assignment 4 Writing a memory manager Due: November 16, 11:30 PM Goals To understand the nuances of building a memory allocator. To create a shared library. Background

More information

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017

POSIX Shared Memory. Linux/UNIX IPC Programming. Outline. Michael Kerrisk, man7.org c 2017 November 2017 Linux/UNIX IPC Programming POSIX Shared Memory Michael Kerrisk, man7.org c 2017 mtk@man7.org November 2017 Outline 10 POSIX Shared Memory 10-1 10.1 Overview 10-3 10.2 Creating and opening shared memory

More information

CPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2

CPSC 213. Introduction to Computer Systems. Winter Session 2017, Term 2. Unit 1c Jan 24, 26, 29, 31, and Feb 2 CPSC 213 Introduction to Computer Systems Winter Session 2017, Term 2 Unit 1c Jan 24, 26, 29, 31, and Feb 2 Instance Variables and Dynamic Allocation Overview Reading Companion: Reference 2.4.4-5 Textbook:

More information