What is the difference between mmap and malloc? - ProProfs Discuss
Advertisement

What is the difference between mmap and malloc?

What is the difference between mmap and malloc?

Change Image    Delete

Asked by R. Jones, Last updated: Nov 09, 2024

+ Answer
Request
Question menu
Vote up Vote down

2 Answers

H. Barnes

H. Barnes

Subscribe to Pewdiepie

H. Barnes
H. Barnes, Unemployed, Barnes, Atlanta

Answered Aug 01, 2019

The Malloc (main memory allocation point)is the main memory allocation interface. It is the best to allocate memory and returns a pointer to the freshly available memory. mmap and malloc are memory-related terms in a UNIX system. mmap refers to a memory mapping system that has its own unique I/O. It reads a file from disk, loads it into memory, and presents a memory-mapped file.

The Malloc (main memory allocation point)is the main memory allocation interface. It is the best to
The memory section can either be read-only or writable. mmap is not recommended for allocation of memory. mmap can also be used to speed up responses given by applications, but this comes at the expenses of losing some byte to pages so that applications can run smoothly.

upvote downvote
Reply 

F. Daniel

F. Daniel

I work for a California based MNC.

F. Daniel
F. Daniel, Content Optimization Executive, Diploma in Journalism, California

Answered Jul 16, 2019

"Malloc" stands for main memory allocation point, while "mmap" denotes a memory mapped system that has its own unique I/O. Though these two seem to be performing the same functions, still there are some differences between them, basically on functionality. Malloc is the main memory allocation interface, which is the largest in the C library. Malloc generally functions in many of the memory management processes, and mmap uses the context switch which converts into kernel land.


As against the use of mmap, malloc is best used for the allocation of memory in the running of any application on the system. Though not advisable because it sacrifices some bytes to pages, but mmap can be used to increase the speed of response received by the application. It is costly to use mmap to allocate memory basically due to data allocation and deallocation in the chunks. The memory used by malloc does not return to the OS, only if there is a segment break in data; but mmap returns the memory it has used. This gives mmap more advantage than malloc.

upvote downvote
Reply 

Advertisement
Advertisement
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader
Image Preview
Search for Google images Google Image Icon
Select a recommended image
Upload from your computer Loader

Email Sent
We have sent an email to your address "" with instructions to reset your password.