Skip to content
Snippets Groups Projects
Commit 481cbd51 authored by Elias Pipping's avatar Elias Pipping
Browse files

Use `mmap()` because it works on Linux and OS X

The combination of `posix_memalign` and `mprotect` does not work as
expected on OS X, see also !43.
parent f40d8e51
No related branches found
No related tags found
No related merge requests found
......@@ -106,7 +106,7 @@ namespace Dune
it->capacity << " bytes at " << it->ptr << std::endl;
error = true;
}
free(it->page_ptr);
munmap(it->page_ptr, it->pages * page_size);
}
if (error)
allocation_error("lost allocations");
......@@ -122,8 +122,10 @@ namespace Dune
ai.pages = (ai.capacity) / page_size + 2;
ai.not_free = true;
size_type overlap = ai.capacity % page_size;
int result = posix_memalign(&(ai.page_ptr), page_size, ai.pages * page_size);
if (0 != result)
ai.page_ptr = mmap(NULL, ai.pages * page_size,
PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if (MAP_FAILED == ai.page_ptr)
{
throw std::bad_alloc();
}
......@@ -171,7 +173,7 @@ namespace Dune
memprotect(it->page_ptr,
(it->pages) * page_size,
PROT_READ | PROT_WRITE);
std::free(it->page_ptr);
munmap(it->page_ptr, it->pages * page_size);
// remove chunk info
allocation_list.erase(it);
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment