I plan to use mmap() to allocate a buffer close to a specific address.
What I'm worried about is, the buffer allocated using mmap() will overlap other buffers allocated by malloc() or new operator (C++). Is it possible?
If you use MAP_FIXED
to demand mmap
create the mapping at a particular address, then yes it is possible that you overwrite an existing mapping such as space allocated by malloc
, part of a shared library's code or data section, etc. Basically it's always an error to use MAP_FIXED
unless you've already obtained the address range via a call to mmap
without specifying MAP_FIXED
(so you know it belongs to you); in this case you can intentionally overwrite parts of the mapping using MAP_FIXED
).
The other answers all seemed to miss the fact that you said "close to a specific address", which to me implies MAP_FIXED
. If you're not using MAP_FIXED
, please elaborate on how you're obtaining a mapping "close to a specific address".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With