Find Jobs
Hire Freelancers

Dynamic memory allocation program in C - 31/10/2017 00:14 EDT

₹100-400 INR / hour

Lezárt
Kiadva ekkor: több mint 6 évvel ezelőtt

₹100-400 INR / hour

For this assignment, you will be given the structure for a simple shared library that is used in place of the heap memory allocation functions malloc() and free(). You'll code two functions in this library, named Mem_Alloc() and Mem_Free(). Memory Allocation BACKGROUND Memory allocators have two distinct tasks. First, the memory allocator uses the sbrk() system call to ask the operating system to expand the heap segment of the its virtual address space. However in the code we've provided, we use mmap() to simulate a process's heap in the memory-mapped segment. Second, the memory allocator manages this memory by maintaining the internal structure of the heap including tracking the size and status of each block. When the process makes a request for heap memory, the allocator searches its list of heap blocks for one that is large enough to satisfy the request. The chosen block may be split into two smaller ones before having its status set to allocated. Later when process frees memory, the allocator changes the block's status to freed and may coalesce it with free neighbors to make larger blocks. This memory allocator is usually provided as part of a standard library rather than being part of the operating system. Thus, the memory allocator operates entirely within the virtual address space of a single process and knows nothing about which physical memory pages have been allocated to this process or the mapping from virtual addresses to physical addresses. The C programming language defines its allocator with the functions malloc() and free() found in "stdlib.h" as follows: void *malloc(size_t s): allocates s bytes and returns a pointer to the allocated memory. The memory is not cleared. void free(void *ptr): frees the memory pointed to by ptr that was previously allocated by malloc() (or calloc() or realloc()). The behaviour is undefined if ptr is a stray pointer or if an attempt is made to free an allocation more than once. If ptr is NULL, the function does nothing and simply returns. UNDERSTAND the Code Copy the entire contents from following directory into your working directory for this assignment: /p/course/cs354-skrentny/public/code/p3 In this directory you'll find the files named "Makefile", "mem.c" and "mem.h" as well as a directory named "tests". In "mem.c" is the completed code for two functions: Mem_Init(int sizeOfRegion) and Mem_Dump(). Look at these functions to understand what they do and how they do it. Also note the global block header pointer first_block is the head of our list of memory blocks, where each block would be marked as either free or allocated. Very carefully read the comments for the provided block tag structure to understand the conventions used in this program. These functions we've completed are described below: Mem_Init(int sizeOfRegion) This function sets up and initializes the "heap" space that the allocator will manage. sizeOfRegion is the number of bytes desired for the heap. This function should be called once at the start of any main program before calling any of the other allocator functions. In your main programs to test your code call this function first to initialize enough space so that subsequent calls to Mem_Alloc() function properly. The test main programs we've provided (discussed below) already do this.
Projektazonosító: 15525538

A projektről

4 ajánlat
Távolról teljesíthető projekt
Aktiválva: 6 évvel ezelőtt

Szeretne pénzt keresni?

A Freelancer oldalán történő árajánlatadás előnyei

Határozzon meg költségvetést és időkeretet
Kapja meg fizetését a munkáért
Vázolja ajánlatát
Ingyen regisztrálhat és adhat árajánlatot munkákra
4 szabadúszó adott átlagosan ₹333 INR/óra összegű árajánlatot erre a munkára
Felhasználó avatár
4 years of IT experience in software development on Core java, J2EE, Spring, web services, Cobertura, restful interface, JSON, MQTT client, spring MVC, mosquitto, Amazon s3, struts, RESTful, mockito Relevant Skills and Experience 4 years of IT experience in software development on Core java, J2EE, Spring, web services, Cobertura, restful interface, JSON, MQTT client, spring MVC, mosquitto, Amazon s3, struts, RESTful, mockito
₹333 INR 10 napon belül
5,0 (5 értékelés)
1,8
1,8
Felhasználó avatár
I have 15 years of development experience with C and C++ on UNIX platform. Given an opportunity, I will prove my skills by delivering the quality code. I am well versed with memory allocators and implemented custom memory allocators in the past.
₹388 INR 40 napon belül
0,0 (0 értékelés)
0,0
0,0

Az ügyfélről

INDIA zászlója
Bangalore, India
4,8
231
Tagság kezdete: jan. 29, 2011

Ügyfél-hitelesítés

Köszönjük! E-mailben elküldtük a linket, melyen átveheti ajándék egyenlegét.
E-mailje elküldése során valami hiba történt. Kérjük, próbálja újra.
Regisztrált Felhasználók Összes Közzétett Munka
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Előnézet betöltése
Hozzáférést adott a helymeghatározáshoz.
Belépési munkamenete lejárt, és kijelentkeztettük. Kérjük, lépjen be újra.