From: Otto Moerbeek Date: Fri, 15 Mar 2019 11:23:00 +0000 (+0100) Subject: Move back to malloc on !OpenBSD. Doing mmap/munmap all the time hurts too much. X-Git-Tag: auth-4.2.0-rc1~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7583%2Fhead;p=thirdparty%2Fpdns.git Move back to malloc on !OpenBSD. Doing mmap/munmap all the time hurts too much. --- diff --git a/pdns/lazy_allocator.hh b/pdns/lazy_allocator.hh index 4851687ba6..68ba53619e 100644 --- a/pdns/lazy_allocator.hh +++ b/pdns/lazy_allocator.hh @@ -43,16 +43,29 @@ struct lazy_allocator { pointer allocate (size_type const n) { +#ifdef __OpenBSD__ void *p = mmap(nullptr, n * sizeof(value_type), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON | MAP_STACK, -1, 0); if (p == MAP_FAILED) throw std::bad_alloc(); return static_cast(p); +#else + return static_cast(::operator new (n * sizeof(value_type))); +#endif } void deallocate (pointer const ptr, size_type const n) noexcept { +#ifdef __OpenBSD__ munmap(ptr, n * sizeof(value_type)); +#else +#if defined(__cpp_sized_deallocation) && (__cpp_sized_deallocation >= 201309) + ::operator delete (ptr, n * sizeof(value_type)); +#else + (void) n; + ::operator delete (ptr); +#endif +#endif } void construct (T*) const noexcept {}