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

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.


Copy the entire contents from following directory into your working directory for this assignment:


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.

Skills: C Programming, C# Programming, C++ Programming, Java, Software Architecture

See more: malloc calloc realloc free in c with example, dynamic array in c using malloc, simple c program for dynamic memory allocation, program using dynamic memory allocation in c++, dynamic memory allocation in c example, malloc in c example, write a c program to find the largest number in array using dynamic memory allocation, dynamic memory allocation in c programming examples, circuit board - 16/05/2017 00:13 EDT, photoediting - 21/03/2017 02:14 EDT, write a c++ program to accept 10 or more numbers then: display the numbers in two columns: one column with the numbers as they w, write a c program to accept 10 or more numbers then display the numbers in two columns one column with the numbers as they were , task allocation program, simulation memory management program, simulation memory allocation algorithms

About the Employer:
( 156 reviews ) Calcutta, India

Project ID: #15525538

8 freelancers are bidding on average ₹360/hour for this job


Hello. Please contanct for me. I am ready for your job. I am an expert on c++ programming. Thank you.

₹666 INR / hour
(17 Reviews)

Hi There, Having good knowledge in C and operating systems. I can do the project of memory allocators in relatively short duration. I am wilking ti it. Please message me for further discussions. Regards, Sneha

₹277 INR / hour
(6 Reviews)

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 an More

₹333 INR / hour
(4 Reviews)
₹332 INR / hour
(2 Reviews)

Iam keen to do this. Please discuss........................................................................

₹333 INR / hour
(1 Review)
₹277 INR / hour
(0 Reviews)

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 me More

₹388 INR / hour
(0 Reviews)
₹277 INR / hour
(0 Reviews)