Find Jobs
Hire Freelancers

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

₹100-400 INR / hour

Ditutup
Dibuat lebih dari 6 tahun yang lalu

₹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.
ID Proyek: 15525538

Tentang proyek

4 proposal
Proyek remot
Aktif 6 tahun yang lalu

Ingin menghasilkan uang?

Keuntungan menawar di Freelancer

Tentukan anggaran dan garis waktu Anda
Dapatkan bayaran atas pekerjaan Anda
Uraikan proposal Anda
Gratis mendaftar dan menawar pekerjaan
4 freelancer menawar dengan rata-rata ₹333 INR/jam untuk pekerjaan ini
Avatar Pengguna
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 dalam 10 hari
5,0 (5 ulasan)
1,8
1,8
Avatar Pengguna
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 dalam 40 hari
0,0 (0 ulasan)
0,0
0,0

Tentang klien

Bendera INDIA
Bangalore, India
4,8
231
Anggota sejak Jan 29, 2011

Verifikasi Klien

Terima kasih! Kami telah mengirim Anda email untuk mengklaim kredit gratis Anda.
Anda sesuatu yang salah saat mengirimkan Anda email. Silakan coba lagi.
Pengguna Terdaftar Total Pekerjaan Terpasang
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Memuat pratinjau
Izin diberikan untuk Geolokasi.
Sesi login Anda telah kedaluwarsa dan Anda sudah keluar. Silakan login kembali.