CSE320 Spring Homework 3

Size: px
Start display at page:

Download "CSE320 Spring Homework 3"

Transcription

1 CSE320 Spring Homework 3 Due Friday 11:59pm Introduction In this homework assig nment you are to create a custom dynamic memory allocator instead of using the built-in one provided by glibc. You will incorporate custom build f lags to tweak the dif f erent kind of strategies used f or your dynamic allocator as discussed in class. You will need to use the f unction sf_sbrk which requests memory f rom the heap. Your library will need to manage the heap space itself. The f unctions malloc, realloc, calloc, free, memalign, valloc, etc are NOT allowed in your implementation. We will check your assignment f or these f unctions. If we f ind that you used these f unctions you will receive a ZERO f or the assignment, no exceptions will be made. A real allocator may use the brk / sbrk calls f or small memory allocations and mmap / munmap f or large allocations. To allow your program to continue to use the other f unctions provided f rom glibc, we provide a saf e wrapper around sbrk. This makes it so that the heap breakpoint does not g et altered by the real allocator and destroy the memory manag ed by your allocator. For this assignment, your implementation MUST ONLY use sf_sbrk to move the heap breakpoint. You must read Chapter 9.9 Dynamic Memory Allocation. This chapter will contain all the inf ormation needed to complete this assignment. Since the textbook has suf f icient inf ormation about the dif f erent strateg ies and implementation details, this document will not repeat the contents of those chapters and will instead ref er you to the sections and pages in the book. If you need additional resources, the f ollowing may be helpf ul: 1. What Every Programmer Should Know About Memory 2. Anatomy of a Program in Memory 3. How the Kernel Manag es Your Memory 4. Page Cache, the Af f air Between Memory and Files

2 Takeaways Af ter completing this homework you should: Understand what f ragmentation is and the dif f erent types of f ragmentation that should occur. Memory padding and alig nment. The inner working s of how a dynamic memory allocator operates. Working with structs and linked lists in C. Working with ERRNO numbers in C. Linking with other object f iles. Getting started Add the f iles located at to your repository. DO NOT CLONE T HIS REPO! Please f ollow the directions f rom HW0 which instruct you on how to correctly add the remote repository contents to your repository. If you do not f ollow these directions you will most likely end up with a g it submodule in your directory or a hw3 directory inside of a hw3 directory (you should have neither of these). Directory structure In the hw3 directory are three f olders: lib, src, and include. This directory structure is a typical organization f or C projects. The lib f older contains any non-standard libraries which are used by the project, and the object f iles created f rom the source f iles in the src directory. The src f older contains supporting C source f iles. The include f older contains all header f iles. In this assig nment you are creating the dynamic memory allocator to replace the standard malloc, free, calloc and realloc f unctions. You are responsible f or implementing sf_malloc,

3 sf_free, sf_calloc and sf_realloc in the src/sfmm.c f ile. We have provided a small sample main f ile which tests your sf mm f unctions, sfmmtest.c which perf orms very basic tests. Af ter your allocator passes the very basic tests in this f ile, you must create your own either by extending the sfmmtest.c or creating your own C f ile entirely. You should examine and understand the Makef ile as it is an example of compiling with non-standard libraries. The provided Makefile creates object f iles f rom all the f iles in the src directory and creates libsf util.a with all the object f iles and the given f ile sfutil.o. The f ile libsf util.a is an example of a static library created using the archiver. Your main program WILL NOT be graded and your Makef ile WILL NOT be used. You must not modif y the f ile sf mm.h, as we will replace this f ile when we perf orm our tests f or grading. If you wish to add things to a header f ile in your program, please make an additional header f ile (in the include directory) which does not conf lict with sfmm.h. Initialization and helper functions In the lib directory we have provided object f iles sfutil.o which you will need to link with your project. This f ile exposes the f ollowing f unctions: * This routine will initialize your memory allocator. It should be called * in your implementation ONCE, before using any of the other sfmm * functions. max_heap_size Unsigned value determining the maximum size of * your heap. void sf_mem_init(size_t max_heap_size); * Extends the heap by increment bytes and returns the start address of * the new area. You cannot shrink the heap using this function. * Calling sf_sbrk() with an increment of 0 can be used to find the current * location of the program break. increment The amount of bytes to increase the size of the heap by. On success, sf_sbrk() returns the previous program break. (If the * break was increased, then this value is a pointer to the start of the

4 * newly allocated memory). On error, (void *) -1 is returned, and errno is * set to ENOMEM. void* sf_sbrk(size_t increment); * Function which outputs the state of the free-list to stdout. * Performs checks on the placement of the header and footer, * and if the memory payload is correctly aligned. * See sf_snapshot section for details on the output format. verbose If true, snapshot will additionally print out * each memory block using the sf_blockprint function. void sf_snapshot(bool verbose); * Function which prints human readable block format * readable format. block Address of the block header in memory. void sf_blockprint(void* block); * Prints human readable block format * from the address of the payload. * IE. subtracts header size from the data pointer to obtain the address * of the block header. Calls sf_blockprint internally to print. data Pointer to payload data in memory (value returned by * sf_malloc). void sf_varprint(void *data); The f unctions sf_mem_init and sf_sbrk must be used to initialize and request memory f or your allocator when it is needed. The f unctions sf_snapshot, sf_blockprint, and sf_varprint are helper f unctions which we have provided to help you visualize your f reelist and allocator blocks. We have also provided additional tests which will check certain properties of each f ree block when a snapshot is being perf ormed if you set the snapshot verbose value to true. It would be in your best interests to make sure your allocated blocks pass all these verbose snapshot tests. sf_mem_init

5 This f unction should be used one time in a program which uses your allocations f unctions. The argument it takes describes how large the maximum heap space given to sf _ sbrk will be. Typically you will want this to be one of the f irst f ew lines of your program. sf_sbrk This is the f unction sf _ malloc, sf _ calloc, and sf _ realloc should be using to request heap space f or your allocator. Its operation is similar to the real system call sbrk. Since giving back heap space is tough using sbrk, it does not accept negative values as an argument (size_ t is unsigned, so any negative numbers will be treated as very large positive numbers). At some point in your program, you may want to f ind where the heap breakpoint currently is. To f ind the current position of the heap breakpoint you should call sf _ sbrk with a size of zero and it will return the address of the current heap breakpoint (without moving it). If sf _ sbrk is unable to return the requested size of memory you asked f or, it will return (void *) -1, and errno will be set to ENOMEM. sf_blockprint and sf_varprint These two f unctions are used to print what a memory block looks like. The f unction sf _ blockprint takes the address of a memory block header. You would typically use this while debug g ing your malloc and f ree implementations which have direct access to the address of the block itself. The f unction sf _ varprint should be used with addresses that are returned by sf _ malloc, sf _ realloc, and sf _ calloc. Internally it adjusts the address f rom the value returned by these f unctions to obtain the address of the block s header, and then calls sf _ blockprint with that address. Below we display the f ormat printed by sf _ blockprint and sf _ varprint. Allocated Block: x bytes x bytes 0001 <- Header % p Payload x bytes x bytes x bytes 0001 <- Footer % p Free Block:

6 x bytes x bytes 0000 <- Header % p Next: %p Prev: %p... x bytes x bytes 0000 <- Footer % p sf_snapshot You will use this f unction to help debug/visualize the f ree-list. It starts by printing out inf ormation about the snapshot: Which kind of f reelist is being used (hard coded to Explicit), the size of the memory row (bytes), and the total space (bytes) taken f rom the heap so f ar. It then prints out the address of the f ree block and how many total bytes allocated f or the entire f reeblock. It will print this f or each node in the f ree list. Snapshot: Explicit # :42 0x7ffe06e2a1b If you call sf _ snapshot with the verbose f lag set to true, it will perf orm the f ollowing additional checks per f reeblock. # Examples of the types of checks that may happen WARN: Dumping header value: 0x # This always prints with verbose. WARN: Dumping footer value: 0x # This always prints with verbose. WARN: The allocated bit on the free node footer is set. WARN: Dumping footer value: 0x WARN: The header and footer have different block sizes. WARN: Header block size: 24 WARN: Footer block size: 0

7 WARN: The payload of the block is not aligned on an address divisible by 16. WARN: The total size of the freeblock is < 32 bytes. WARN: This does not meet the minimum requirements for storing WARN: the block header and footer, and the next and free pointers. If you accidentally have an allocated block in your f reelist, snapshot will tell you the address of which node in the f reelist which is pointing to it, and dump the contents using the sf _ blockprint f unction. ERROR: Snapshot encountered an allocated block in the freelist... ERROR: The freeblock 0x7fff5f91dc20 points to this block bytes 0 bytes 0001 <- Header 0x7fff5f91dc Payload: bytes unused 0 bytes 0000 <- Footer 0x7fff5f91dc ERROR: Aborting snapshot function. The above block being displayed probably happened because the memory was not zeroed out and was never set by anything. The large number being printed in the payload leads us to this conclusion. If the node was the head of the f reelist, the message above will be slightly altered to alert you. ERROR: This node is the head of the freelist. If you call snapshot and the f reelist_ head pointer is NULL, it will tell you that the f reelist is empty. WARN: The freelist has no nodes... We discuss more about the f reelist_ head pointer in the implementation section. Allocation functions

8 You will implement the f ollowing f our f unctions in the f ile sfmm.c. The f ile sfmm.h contains the prototypes and documentation f ound here. * This is your implementation of malloc. It creates dynamic memory which * is aligned and padded properly for the underlying system. This memory * is uninitialized. size The number of bytes requested to be allocated. If successful, the pointer to a valid region of memory * to use is returned, else the value NULL is returned and the * ERRNO is set accordingly. If size is set to zero, then the * value NULL is returned. void* sf_malloc(size_t size); * Marks a dynamically allocated region as no longer in use. * Adds the newly freed block to the free list. ptr Address of memory returned by the function sf_malloc, * sf_realloc, or sf_calloc. void sf_free(void *ptr); * Resizes the memory pointed to by ptr to be size bytes. ptr Address of the memory region to resize. size The minimum size to resize the memory to. If successful, the pointer to a valid region * of memory to use is returned, else the value NULL is * returned and the ERRNO is set accordingly. * * A realloc call with a size of zero should return NULL * and set the ERRNO accordingly. void* sf_realloc(void *ptr, size_t size); * Allocate an array of nmemb elements each of size bytes. * The memory returned is additionally zeroed out. nmemb Number of elements in the array. size The size of bytes of each element. If successful, returns the pointer to a valid * region of memory to use, else the value NULL is returned * and the ERRNO is set accordingly. If nmemb or

9 * size is set to zero, then the value NULL is returned. void* sf_calloc(size_t nmemb, size_t size); Make sure these f unctions have these exact names and arguments. They must also appear in the correct f ile. If you do not name the f unctions correctly with the correct arg uments, your prog ram will not compile when we test it. YOU WILL GET A ZERO. Look throug h /usr/include/asm-generic/errno-base.h and /usr/include/asmgeneric/errno.h f or the def initions of the ERRNO codes. Implementation details During compilation it is possible to pass values which will cause dif f erent f eatures of the allocator to be exercised. We will use dif f erent f lag s/pre-processor directives during the testing process to compile your allocator with dif f erent f unctionality. Your implementation MUST only use sf_sbrk calls of size 4 KB (4 096 bytes). Memory Row Size In this assignment we will assume that each Memory row is 64 -bits in size (1 quad word in x86_64 ). In the book f igures, Figure 9.36 f or example each square represents a memory row. C declaration Intel data type GAS suf f ix x86-64 Size (Bytes) char Byte b 1 short Word w 2 int Double word l 4 unsig ned Double word l 4

10 C declaration Intel data type GAS suf f ix x86-64 Size (Bytes) long int Quad word q 8 unsigned long Quad word q 8 pointer Quad word q 8 f loat Single precision s 4 double Double precision d 8 long double Extended precision t 16 Sizes of types on x86-64 Ubuntu Desktop Edition You can f ind more inf ormation about GAS on the wikipedia and tldp. Note the larg est type is long double. Make sure to take this into consideration when determining the alignment and padding f or your payloads. Freelist head In the f ile sf mm.c there is a pointer declared f reelist_ head, which is made available globally via the extern statement in sf mm.h. You MUST store the head node of your explicit f reelist in this pointer. * You should store the head of your free list in this variable. * Doing so will make it accessible via the extern statement in sfmm.h * which will allow sf_snapshot to access the value from a different * file. sf_free_header* freelist_head = NULL; Block Headers & Footer

11 In Chapter Page 84 7 Figure 9.35, the header is def ined as a single 32-bit double word with the block size and allocated bit. In this assig nment, your header additionally records the requested allocation size (in bytes). The block header is def ined as a singe 64 -bit quad word. The struct f or representing the header is f ound in sfmm.h. #define ALLOC_SIZE_BITS 4 #define BLOCK_SIZE_BITS 28 #define REQST_SIZE_BITS 32 struct attribute (( packed )) sf_header { uint64_t alloc : ALLOC_SIZE_BITS; uint64_t block_size : BLOCK_SIZE_BITS; uint64_t requested_size : REQST_SIZE_BITS; }; typedef struct sf_header sf_header; requested_size block_size a The requested_size f ield is 32-bits. It is the number of bytes requested by the call to sf_malloc. The block_size f ield is 28 bits. It is the number of bytes f or the entire block (header/f ooter, payload, padding). The least-signif icant bit is f or the allocated bit (as explained in the textbook). The block size f ield is only 28 bits, but technically it uses the 000a bits as part of the value. It just assumes these bits are always 0 because the address must be divisible by 16 (alignment f or largest type in x86-64 ). This gives us an actual representation of 32 bits f or the block size. For example, if the requested size is 13 bytes and the block size is 16 bytes the header will be set to: Notice the header will always be at an address which is a multiple of 8 (but not 16) due to payload alignment. This allows us to use the LSB (least signif icant bit) as a f lag f or the allocated state of the block. To assist in accessing the next and f ree pointers of a f ree block, an additional structure sf_free_header is def ined.

12 struct attribute (( packed )) sf_free_header { sf_header header; struct sf_free_header *next; struct sf_free_header *prev; }; typedef struct sf_free_header sf_free_header; Lastly, sfmm.h provides a struct f or representing the f ooter. #define ALLOC_SIZE_BITS 4 #define BLOCK_SIZE_BITS 28 struct attribute (( packed )) sf_footer { uint64_t alloc : ALLOC_SIZE_BITS; uint64_t block_size : BLOCK_SIZE_BITS; /* Other 32-bits are unused }; typedef struct sf_footer sf_footer; Use these structs to access the inf ormation in your memory allocator blocks. Explicit Freelist Management Policy You MUST use an explicit f reelist as described in Chapter Pag e 862 to manag e your memory allocations. If your allocator is compiled with no f lags or if the f lag -DLIFO is provided then your f reelist must manag e the inf ormation in a last-in-f irst-out manner. If your allocator is complied with the f lag -DADDRESS then you will instead manage your f reelist by maintaining the allocations in increasing address order (low address in memory to hig h address in memory). Block Placement Policy Your allocator will support either f irst placement or next placement strateg ies as described in

13 Chapter Pag e If your allocator is compiled with no f lags or -DFIRST then it will use the f irst placement strategy f or locating a f ree block. If your allocator is compiled with the f lag -DNEXT then it will use the next placement strateg y f or locating a f ree block. Coalescing Your implementation should perf orm immediate coalescing as described in Chapter Pag e 850. You should use boundary tags as described in Chapter Pag e 851 to assist in coalescing all f ree memory blocks in an ef f icient manner. In Chapter Page 852 Figure 9.39, the boundary tag (f ooter) is def ined as a single 32-bit double word with the block size and allocated bit. Your boundary tag should be a single memory row of 64 - bits, but contains the same f ormat. Unused block_size a Splitting Your allocator must split blocks which are too large to help reduce the amount of internal f ragmentation. You can f ind the details f or this mechanic in Chapter Page Do not make splinters! Splinters are a small (< 16 bytes, in this case) group of f ree bytes lef t af ter inserting a relatively larg e payload into a f ree space. To avoid this you over allocate the amount of memory requested so these small, potentially useless blocks are not inserted into the f ree list. Summary of Memory Block Format

14 Hints HUGE sized allocations: any requests larger than 4GB should return an error. If there s not enough memory to give, f ail and set the ERRNO correctly. Make sure that memory returned is alig ned and padded correctly f or the system in use. Make sure that if no preprocessor directives are g iven that your prog ram still works. Test your program with dif f erent combinations of f lags to see if it still works correctly. What if someone f rees NULL or in the middle of an allocation block or a non-sf _allocated address? Your program should not crash or segf ault if this happens, so you should check and make sure a call to f ree is on a valid address bef ore you f ree it.

15 When encountering edge cases you can make small test programs and observe how malloc and free will behave and emulate accordingly. Hand-in instructions You are expected to hand in at minimum the f ollowing f iles in your git submission. 1. The f iles sfmm.c and sfmm.h. All additional f iles that you may of created *.c or *.h should also be included. 2. Makefile 3. README.md Your assignment is expected to work on the f ollowing platf orms: 1. Ubuntu Desktop x86_ Submitting your assignment REMEMBER Do not submit at the last minute. We will be using the time stamp of the commit associated with the tag to determine if your homework assignment is late or not. On top of that we will NOT GRADE late assignments 1. Make sure all f iles f or this assignment are in a hw3 directory. 2. To tag your submission, make sure f irst that you have pulled f rom the remote and all code changes are merged. Once everything is merged, push it back to the remote server. Be sure you are done making any and all changes bef ore proceeding. T ags cannot be deleted. 3. Log on to your gitlab account and navigate to the tags page f rom your repository s main page. 4. Here you can click the green New T ag button. 5. Enter hw3 f or the tag name, the name of your current branch (typically master ) and an optional completion message. Do not put important inf ormation in the message as we will not necessarily see it. Any relevant inf ormation to your submission should be in your hw3/readme.md 6. To check if you submitted properly, you should now see a hw3 tag in the list of tags f or your repository.

16 When writing your program try to comment as much as possible. Try to stay consistent with your f ormatting. It is much easier f or your TA and the prof essor to help you if we can f igure out what your code does quickly.

CS201: Lab #4 Writing a Dynamic Storage Allocator

CS201: Lab #4 Writing a Dynamic Storage Allocator CS201: Lab #4 Writing a Dynamic Storage Allocator In this lab you will write a dynamic storage allocator for C programs, i.e., your own version of the malloc, free and realloc routines. You are encouraged

More information

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date 1 Introduction In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the

More information

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM

CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM CSE 351, Spring 2010 Lab 7: Writing a Dynamic Storage Allocator Due: Thursday May 27, 11:59PM 1 Instructions In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version

More information

Writing a Dynamic Storage Allocator

Writing a Dynamic Storage Allocator Project 3 Writing a Dynamic Storage Allocator Out: In class on Thursday, 8 Oct 2009 Due: In class on Thursday, 22 Oct 2009 In this project, you will be writing a dynamic storage allocator for C programs,

More information

COMP 321: Introduction to Computer Systems

COMP 321: Introduction to Computer Systems Assigned: 3/8/18, Due: 3/29/18 Important: This project may be done individually or in pairs. Be sure to carefully read the course policies for assignments (including the honor code policy) on the assignments

More information

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM

ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM ECE454, Fall 2014 Homework3: Dynamic Memory Allocation Assigned: Oct 9th, Due: Nov 6th, 11:59PM The TA for this assignment is Xu Zhao (nuk.zhao@mail.utoronto.ca). 1 Introduction OptsRus is doing really

More information

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016

Malloc Lab & Midterm Solutions. Recitation 11: Tuesday: 11/08/2016 Malloc Lab & Midterm Solutions Recitation 11: Tuesday: 11/08/2016 Malloc 2 Important Notes about Malloc Lab Malloc lab has been updated from previous years Supports a full 64 bit address space rather than

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

CS 3214, Fall 2015 Malloc Lab: Writing a Dynamic Storage Allocator Due date: November 16, 2014, 11:59pm

CS 3214, Fall 2015 Malloc Lab: Writing a Dynamic Storage Allocator Due date: November 16, 2014, 11:59pm CS 3214, Fall 2015 Malloc Lab: Writing a Dynamic Storage Allocator Due date: November 16, 2014, 11:59pm 1 Introduction In this lab you will be writing a dynamic storage allocator for C programs, i.e.,

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

Project 2. Assigned: 02/20/2015 Due Date: 03/06/2015

Project 2. Assigned: 02/20/2015 Due Date: 03/06/2015 CSE 539 Project 2 Assigned: 02/20/2015 Due Date: 03/06/2015 Building a thread-safe memory allocator In this project, you will implement a thread-safe malloc library. The provided codebase includes a simple

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

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator

Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator 1. Introduction Spring 2016, Malloc Lab: Writing Dynamic Memory Allocator Assigned: Mar. 03 Due: Mar. 17, 15:59 In this lab you will be writing a dynamic memory allocator for C programs, i.e., your own

More information

CSE 361 Fall 2017 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday Nov. 13, Due: Monday Dec. 05, 11:59PM

CSE 361 Fall 2017 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday Nov. 13, Due: Monday Dec. 05, 11:59PM CSE 361 Fall 2017 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday Nov. 13, Due: Monday Dec. 05, 11:59PM 1 Introduction In this lab you will be writing a dynamic storage allocator for C

More information

Lab 1: Dynamic Memory: Heap Manager

Lab 1: Dynamic Memory: Heap Manager Lab 1: Dynamic Memory: Heap Manager Introduction to Systems, Duke University 1 Introduction For this lab you implement a basic heap manager. The standard C runtime library provides a standard heap manager

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

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date

CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date CS 105 Malloc Lab: Writing a Dynamic Storage Allocator See Web page for due date 1 Introduction In this lab you will be writing a dynamic storage allocator for C programs, i.e., your own version of the

More information

CSE 361S Intro to Systems Software Final Project

CSE 361S Intro to Systems Software Final Project Due: Tuesday, December 9, 2008. CSE 361S Intro to Systems Software Final Project In this project, you will be writing a dynamic storage allocator for C programs (i.e., your own version of malloc, free,

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

Shell Project, part 3 (with Buddy System Memory Manager) ( points)

Shell Project, part 3 (with Buddy System Memory Manager) ( points) CS 453: Operating Systems Project 6 Shell Project, part 3 (with Buddy System Memory Manager) (120 140 points) Due Date -On Class Home Page 1 Introduction In the last release of the mini-shell we will provide

More information

CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM

CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM CSCI 2021, Fall 2018 Malloc Lab: Writing a Dynamic Storage Allocator Assigned: Monday November 5th Due: Monday November 19th, 11:55PM 1 Introduction In this lab you will be writing a dynamic storage allocator

More information

Memory management. Johan Montelius KTH

Memory management. Johan Montelius KTH Memory management Johan Montelius KTH 2017 1 / 22 C program # include int global = 42; int main ( int argc, char * argv []) { if( argc < 2) return -1; int n = atoi ( argv [1]); int on_stack

More information

UW CSE 351, Winter 2013 Final Exam

UW CSE 351, Winter 2013 Final Exam Full Name: Student ID #: UW CSE 351, Winter 2013 Final Exam March 20, 2013 2:30pm - 4:20pm Instructions: Write your full name and UW student ID number on the front of the exam. When the exam begins, make

More information

Project 4: Implementing Malloc Introduction & Problem statement

Project 4: Implementing Malloc Introduction & Problem statement Project 4 (75 points) Assigned: February 14, 2014 Due: March 4, 2014, 11:59 PM CS-3013, Operating Systems C-Term 2014 Project 4: Implementing Malloc Introduction & Problem statement As C programmers, we

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

CSCI0330 Intro Computer Systems Doeppner. Project Malloc. Due: 11/28/18. 1 Introduction 1. 2 Assignment Specification Support Routines 4

CSCI0330 Intro Computer Systems Doeppner. Project Malloc. Due: 11/28/18. 1 Introduction 1. 2 Assignment Specification Support Routines 4 Project Malloc Due: 11/28/18 1 Introduction 1 2 Assignment 2 2.1 Specification 2 2.2 Support Routines 4 3 The Trace-driven Driver Program (mdriver) 6 4 Using the REPL 6 5 Programming Rules 7 6 GDB 7 6.1

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

Project 3a: Malloc and Free

Project 3a: Malloc and Free Project 3a: Malloc and Free DUE 03/17 at 11:59 PM One late day allowed for submission without any penalty Objectives There are four objectives to this part of the assignment: Note To understand the nuances

More information

CSE351 Spring 2010 Final Exam (9 June 2010)

CSE351 Spring 2010 Final Exam (9 June 2010) CSE351 Spring 2010 Final Exam (9 June 2010) Please read through the entire examination first! We designed this exam so that it can be completed in 100 minutes and, hopefully, this estimate will prove to

More information

Assignment 5. CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am

Assignment 5. CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am 1. Collaboration Policy Assignment 5 CS/ECE 354 Spring 2016 DUE: April 22nd (Friday) at 9 am For this assignment, you may work in pairs (2 people). All students (whether working in a pair or not) must

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

1 Introduction. 2 Logistics. 3 Hand Out Instructions

1 Introduction. 2 Logistics. 3 Hand Out Instructions CS 153, Winter 2018 Malloc Lab: Writing a Dynamic Storage Allocator Due: Last Friday in final s week. No slack days Graded by Interview on the same Friday or over weekend Nael Abu-Ghazaleh (nael@cs.ucr.edu)

More information

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef

advanced data types (2) typedef. today advanced data types (3) enum. mon 23 sep 2002 defining your own types using typedef today advanced data types (1) typedef. mon 23 sep 2002 homework #1 due today homework #2 out today quiz #1 next class 30-45 minutes long one page of notes topics: C advanced data types dynamic memory allocation

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

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

There are 16 total numbered pages, 7 Questions. You have 2 hours. Budget your time carefully!

There are 16 total numbered pages, 7 Questions. You have 2 hours. Budget your time carefully! UNIVERSITY OF TORONTO FACULTY OF APPLIED SCIENCE AND ENGINEERING MIDTERM EXAMINATION, October 27, 2014 ECE454H1 Computer Systems Programming Closed book, Closed note No programmable electronics allowed

More information

CS61, Fall 2012 Section 2 Notes

CS61, Fall 2012 Section 2 Notes CS61, Fall 2012 Section 2 Notes (Week of 9/24-9/28) 0. Get source code for section [optional] 1: Variable Duration 2: Memory Errors Common Errors with memory and pointers Valgrind + GDB Common Memory Errors

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

CS 213, Fall 2002 Malloc Lab: Writing a Debugging Dynamic Storage Allocator Assigned: Fri Nov. 1, Due: Tuesday Nov. 19, 11:59PM

CS 213, Fall 2002 Malloc Lab: Writing a Debugging Dynamic Storage Allocator Assigned: Fri Nov. 1, Due: Tuesday Nov. 19, 11:59PM CS 213, Fall 2002 Malloc Lab: Writing a Debugging Dynamic Storage Allocator Assigned: Fri Nov. 1, Due: Tuesday Nov. 19, 11:59PM Anubhav Gupta (anubhav@cs.cmu.edu) is the lead person for this assignment.

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

CSE351 Spring 2010 Final Exam (9 June 2010)

CSE351 Spring 2010 Final Exam (9 June 2010) CSE351 Spring 2010 Final Exam (9 June 2010) Please read through the entire examination first! We designed this exam so that it can be completed in 100 minutes and, hopefully, this estimate will prove to

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 11: Structures and Memory (yaseminb@kth.se) Overview Overview Lecture 11: Structures and Memory Structures Continued Memory Allocation Lecture 11: Structures and Memory Structures Continued Memory

More information

Machine Problem 1: A Simple Memory Allocator

Machine Problem 1: A Simple Memory Allocator Machine Problem 1: A Simple Memory Allocator Introduction In this machine problem, you are to develop a simple memory allocator that implements the functions my malloc() and my free(), very similarly to

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

Installation of SAP Solution Manager in Windows platform compatible with Amazon / Azure Cloud / Hyper-V / Standalone server

Installation of SAP Solution Manager in Windows platform compatible with Amazon / Azure Cloud / Hyper-V / Standalone server sapbasisf o rbe ginne r.co m http://www.sapbasisfo rbeginner.co m/2013/09/installatio n-o f-sap-so lutio n-manager-in.html Installation of SAP Solution Manager in Windows platform compatible with Amazon

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. 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

Laboratory Assignment #3. Extending scull, a char pseudo-device

Laboratory Assignment #3. Extending scull, a char pseudo-device Laboratory Assignment #3 Extending scull, a char pseudo-device Value: (See the Grading section of the Syllabus.) Due Date and Time: (See the Course Calendar.) Summary: This is your first exercise that

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

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

ECE 2400 Computer Systems Programming, Fall 2018 PA2: List and Vector Data Structures

ECE 2400 Computer Systems Programming, Fall 2018 PA2: List and Vector Data Structures School of Electrical and Computer Engineering Cornell University revision: 2018-09-25-13-37 1. Introduction The second programming assignment is designed to give you experience working with two important

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

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

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Allocating Space

CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Allocating Space CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-1-0) Allocating Space Dynamic Memory Allocation All variables, arrays, structures and unions that we worked with so far are statically allocated,

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

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

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. 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

C Structures & Dynamic Memory Management

C Structures & Dynamic Memory Management C Structures & Dynamic Memory Management Goals of this Lecture Help you learn about: Structures and unions Dynamic memory management Note: Will be covered in precepts as well We look at them in more detail

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

CSCI 237 Sample Final Exam

CSCI 237 Sample Final Exam Problem 1. (12 points): Multiple choice. Write the correct answer for each question in the following table: 1. What kind of process can be reaped? (a) Exited (b) Running (c) Stopped (d) Both (a) and (c)

More information

Memory and C/C++ modules

Memory and C/C++ modules Memory and C/C++ modules From Reading #5 and mostly #6 More OOP topics (templates; libraries) as time permits later Program building l Have: source code human readable instructions l Need: machine language

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

Project 2 Overview: Part A: User space memory allocation

Project 2 Overview: Part A: User space memory allocation Project 2 Overview: Once again, this project will have 2 parts. In the first part, you will get to implement your own user space memory allocator. You will learn the complexities and details of memory

More information

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

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

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

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

CSE351 Autumn 2013 Final Exam (11 Dec 2013)

CSE351 Autumn 2013 Final Exam (11 Dec 2013) CSE351 Autumn 2013 Final Exam (11 Dec 2013) Please read through the entire examination first! We designed this exam so that it can be completed in approximately 90 minutes and, hopefully, this estimate

More information

Advanced Memory Allocation

Advanced Memory Allocation Advanced Memory Allocation Call some useful functions of the GNU C library to save precious memory and to find nasty bugs. by Gianluca Insolvibile Dealing with dynamic memory traditionally has been one

More information

Creating a String Data Type in C

Creating a String Data Type in C C Programming Creating a String Data Type in C For this assignment, you will use the struct mechanism in C to implement a data type that models a character string: struct _String { char data; dynamically-allocated

More information

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA   === Homework submission instructions === Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA email: dsa1@csientuedutw === Homework submission instructions === For Problem 1, submit your source code, a Makefile to compile

More information

Reminder: compiling & linking

Reminder: compiling & linking Reminder: compiling & linking source file 1 object file 1 source file 2 compilation object file 2 library object file 1 linking (relocation + linking) load file source file N object file N library object

More information

COMP26120: Linked List in C (2018/19) Lucas Cordeiro

COMP26120: Linked List in C (2018/19) Lucas Cordeiro COMP26120: Linked List in C (2018/19) Lucas Cordeiro lucas.cordeiro@manchester.ac.uk Linked List Lucas Cordeiro (Formal Methods Group) lucas.cordeiro@manchester.ac.uk Office: 2.28 Office hours: 10-11 Tuesday,

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

1. Introduction. 2. Deliverables

1. Introduction. 2. Deliverables 16.216: ECE Application Programming Summer 2014 Programming Assignment #10: Doubly-Linked Lists Due Friday, 6/27/14, 12:00 PM (noon) NO LATE ASSIGNMENTS 1. Introduction This assignment deals with the combination

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

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

1. Overview This project will help you understand address spaces and virtual memory management.

1. Overview This project will help you understand address spaces and virtual memory management. Project 2--Memory Worth: 12 points Assigned: Due: 1. Overview This project will help you understand address spaces and virtual memory management. In this project, you will implement an external pager,

More information

Lab 03 - x86-64: atoi

Lab 03 - x86-64: atoi CSCI0330 Intro Computer Systems Doeppner Lab 03 - x86-64: atoi Due: October 1, 2017 at 4pm 1 Introduction 1 2 Assignment 1 2.1 Algorithm 2 3 Assembling and Testing 3 3.1 A Text Editor, Makefile, and gdb

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

Carnegie Mellon. Malloc Boot Camp. Stan, Nikhil, Kim

Carnegie Mellon. Malloc Boot Camp. Stan, Nikhil, Kim Malloc Boot Camp Stan, Nikhil, Kim Agenda Carnegie Mellon Conceptual Overview Explicit List Segregated list Splitting, coalescing Hints on hints Advanced debugging with GDB Fun GDB tricks Writing a good

More information

CSE351 Spring 2018, Final Exam June 6, 2018

CSE351 Spring 2018, Final Exam June 6, 2018 CSE351 Spring 2018, Final Exam June 6, 2018 Please do not turn the page until 2:30. Last Name: First Name: Student ID Number: Name of person to your left: Name of person to your right: Signature indicating:

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Macros and Preprocessor. CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang

Macros and Preprocessor. CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang Macros and Preprocessor CGS 3460, Lecture 39 Apr 17, 2006 Hen-I Yang Previously Operations on Linked list (Create and Insert) Agenda Linked List (More insert, lookup and delete) Preprocessor Linked List

More information

Programming Assignment Multi-Threading and Debugging 2

Programming Assignment Multi-Threading and Debugging 2 Programming Assignment Multi-Threading and Debugging 2 Due Date: Friday, June 1 @ 11:59 pm PAMT2 Assignment Overview The purpose of this mini-assignment is to continue your introduction to parallel programming

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

SmartHeap for Multi-Core

SmartHeap for Multi-Core SmartHeap for Multi-Core Getting Started and Platform Guide for Linux Version 11.2 SmartHeap and HeapAgent are trademarks of Compuware Corporation. All other trademarks are the property of their respective

More information

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store)

19-Nov CSCI 2132 Software Development Lecture 29: Linked Lists. Faculty of Computer Science, Dalhousie University Heap (Free Store) Lecture 29 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 29: Linked Lists 19-Nov-2018 Location: Chemistry 125 Time: 12:35 13:25 Instructor: Vlado Keselj Previous

More information

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function CMPT 127 Spring 2019 Grade: / 20 First name: Last name: Student Number: Lab Exam 1 D400 1. [1 mark] Give an example of a sample input which would make the function scanf( "%f", &f ) return -1? Answer:

More information

Arrays, Pointers and Memory Management

Arrays, Pointers and Memory Management Arrays, Pointers and Memory Management EECS 2031 Summer 2014 Przemyslaw Pawluk May 20, 2014 Answer to the question from last week strct->field Returns the value of field in the structure pointed to by

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

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

Problem 1 (Void * generics) (24 points) (suggested time: 30 minutes)

Problem 1 (Void * generics) (24 points) (suggested time: 30 minutes) Problem 1 (Void * generics) (24 points) (suggested time: 30 minutes) Given a sorted void * array of elements, the remove_duplicates function will remove all duplicates in the array, returning the new size

More information

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36

C: Pointers, Arrays, and strings. Department of Computer Science College of Engineering Boise State University. August 25, /36 Department of Computer Science College of Engineering Boise State University August 25, 2017 1/36 Pointers and Arrays A pointer is a variable that stores the address of another variable. Pointers are similar

More information

15-213/18-243, Spring 2011 Exam 2

15-213/18-243, Spring 2011 Exam 2 Andrew login ID: Full Name: Section: 15-213/18-243, Spring 2011 Exam 2 Thursday, April 21, 2011 v2 Instructions: Make sure that your exam is not missing any sheets, then write your Andrew login ID, full

More information

HW2d Project Addenda

HW2d Project Addenda HW2d Project Addenda CS 320 Note the following differences between the project description for Harvard s CS 175 class and our class: 1. The CS 175 due date is not applicable. 2. The starter code location

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

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

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads

CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads CSCI 4210 Operating Systems CSCI 6140 Computer Operating Systems Homework 3 (document version 1.2) Multi-threading in C using Pthreads Overview This homework is due by 11:59:59 PM on Tuesday, April 10,

More information

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21

C: Pointers. C: Pointers. Department of Computer Science College of Engineering Boise State University. September 11, /21 Department of Computer Science College of Engineering Boise State University September 11, 2017 1/21 Pointers A pointer is a variable that stores the address of another variable. Pointers are similar to

More information