K
K
Kirill Batalin2016-03-21 18:39:24
C++ / C#
Kirill Batalin, 2016-03-21 18:39:24

Where is the string returned by mmap(2) stored?

And is it necessary to free the memory at this pointer using free()?

char *ptr = mmap(NULL, fileLength, PROT_READ, MAP_PRIVATE, input, 0);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MiiNiPaa, 2016-03-21
@MiiNiPaa

Why not read the documentation.
man7.org/linux/man-pages/man2/mmap.2.html
1) mmap does not return a string. It returns a pointer to the beginning of the mapped area (void*).
2) It is not necessary to release the area, it will be freed when the process is completed. But if you want, there is unmap.
3) It is strictly forbidden to call free on something not allocated by malloc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question