Question

Provide an overview of memory allocation and the services (allocation and deallocation) provided by the memory...

Provide an overview of memory allocation and the services (allocation and deallocation) provided by the memory manager.

size = 1024 // 1,024 bytes pointer = malloc( size ) // allocate size bytes of memory if pointer is NULL raise_error no_memory // not enough memory! … // use the memory free( pointer ) // release the memory

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • There are two ways to assign memory for the program, one is statically allocated memory and other one is dynamically allocated memory.
  • Statically allocated memory is the allocated memory location, which can not be changed during the run time of the program, where as the dynamically allocated memory has the advantage of allocating, deallocating and resizing of the memory during the run time of the program.
  • For the Dynamic Memory Allocation in the C programing, there four function. malloc(), calloc(), free() and realloc().
  • malloc() function is useful for dynamically allocating a large block of the memory with a particular size, the size of memory is passed as an argument to the function. When the function allocates the memory successfully, then it returns the starting address of the memory. If the memory is not allocated due to unavailability of the memory , then function returns NULL pointer.
  • calloc() is contiguous allocation of memory, where the dynamic memory is allocate in particular number of blocks. As the memory is allocated, it is initialized with the default value '0'.
  • free() function is useful in de-allocation of the memory. Whenever memory allocation occurs using malloc() or calloc() function, then it is not deallocated on its own, it is programmer jobs to deallocate the dynamically allocated memory after its use.
  • realloc() function is useful in resizing the dynamically allocated memory.
  • Please note that the dynamic memory is allocated from the Heap section of the memory.

Code:

size = 1024

pointer = malloc(size)

free(pointer)

Explanation:

  • The size variable is assigned with 1024 value.
  • malloc() function allocates the 1024 bytes of memory and store the starting address of the memory in the pointer.
  • using the free() function, the dynamically allocated memory is deallocated.
Add a comment
Know the answer?
Add Answer to:
Provide an overview of memory allocation and the services (allocation and deallocation) provided by the memory...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE...

    In this assignment, you will implement a Memory Management System(MMS). Using C Programming Language..... MAKE SURE YOU USE C PROGRAMMING Your MMS will handle all requests of allocation of memory space by different users (one thread per user) …. HINT(You will use Pthreads and Semaphores). Your MMS will provide the user with an interface for making memory requests and also for freeing up memory that is no longer needed by the user. One of the jobs of your memory management...

  • Question 11 pts Fill in the blank. Two functions are defined main.c and MyAge.c   // FILE...

    Question 11 pts Fill in the blank. Two functions are defined main.c and MyAge.c   // FILE main.c main ( ) { _______ int age ; printf ( " the value of age is %d \n", age ) ; } // FILE MyAge.c int age = 10; int MyAge ( ) { } Group of answer choices static external internal extern Flag this Question Question 21 pts Fill in the blank. Two functions are defined main.c and MyAge.c   The below program...

  • Malloc function For the prelab assignment and the lab next week use malloc function to allocate...

    Malloc function For the prelab assignment and the lab next week use malloc function to allocate space (to store the string) instead of creating fixed size character array. malloc function allows user to allocate memory (instead of compiler doing it by default) and this gives more control to the user and efficient allocation of the memory space. Example int *ptr ptr=malloc(sizeof(int)*10); In the example above integer pointer ptr is allocated a space of 10 blocks this is same as creating...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification:...

    CS 241 Program 03 Due: Thursday, October 18th Main topics: Arrays& Pointers Memory allocation ram Specification: A stack is a container that can be defined in terms of an array where all adds are preformed at the end of the sequence of existing values, and all removes are also preformed at end of the sequence of existing values. An empty stack is one that has no existing values in the array at all. We use the notion of top of...

  • Working on a program where my task is to implement a library (as a set of...

    Working on a program where my task is to implement a library (as a set of source and header files, documentation, and a Makefile) that provides a few useful functions for working with a counted string data structure. And one of the functions that needs to be written is described below but I am having a little difficulty writing it. Program needs to be written in C. Struct: typedef struct {    char *data;    size_t length; } kstring; function:...

  • Introduction: One of the most important uses of pointers is for dynamic allocation of memory. In...

    Introduction: One of the most important uses of pointers is for dynamic allocation of memory. In C++ there are commands that let the user request a chunk of memory from the operating system, and use this memory to store data. There are also commands to return memory back to the O/S when the program is finished using the data. In this lab, we will explore some of the things that can go wrong when using dynamic memory and discuss how...

  • IN C ONLY As mentioned earlier there are two changes we are going to make from...

    IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...

  • **C PROGRAM*** Q: Which of these changes will improve the memory utilization of a malloc implementation?...

    **C PROGRAM*** Q: Which of these changes will improve the memory utilization of a malloc implementation? 1. Making the free function do nothing 2. Increasing the alignment requirement for objects 3. Changing from an implicit to an explicit free list 4. Adding footer boundary tags in addition to headers 5. Using a best-fit instead of a first-fit search Q: It is possible to use garbage collection with C programs, but with this limitation: 1. The size of an object cannot...

  • Please explain your answer Question 5 - Free Space Management Free space management involves capturing a...

    Please explain your answer Question 5 - Free Space Management Free space management involves capturing a description of the computer's using a data structure, storing this data structure in memory, and OS support to rap this structure to determine an appropriate location for implementation is very important when we scale up the number of operatior required to perform. free memory idly use new memory allocations. An efficient s the OS is Consider the use of a linked list for a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT