1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style license that can be
8 // found in the LICENSE file. See the AUTHORS file for names of contributors.
10 #ifndef ROCKSDB_JEMALLOC
11 # error This file can only be part of jemalloc aware build
15 #include "jemalloc/jemalloc.h"
16 #include "port/win/port_win.h"
18 #if defined(ZSTD) && defined(ZSTD_STATIC_LINKING_ONLY)
20 #if (ZSTD_VERSION_NUMBER >= 500)
23 void* JemallocAllocateForZSTD(void* /* opaque */, size_t size
) {
24 return je_malloc(size
);
26 void JemallocDeallocateForZSTD(void* /* opaque */, void* address
) {
29 ZSTD_customMem
GetJeZstdAllocationOverrides() {
30 return {JemallocAllocateForZSTD
, JemallocDeallocateForZSTD
, nullptr};
33 } // namespace rocksdb
34 #endif // (ZSTD_VERSION_NUMBER >= 500)
35 #endif // defined(ZSTD) defined(ZSTD_STATIC_LINKING_ONLY)
37 // Global operators to be replaced by a linker when this file is
38 // a part of the build
42 void* jemalloc_aligned_alloc(size_t size
, size_t alignment
) ROCKSDB_NOEXCEPT
{
43 return je_aligned_alloc(alignment
, size
);
45 void jemalloc_aligned_free(void* p
) ROCKSDB_NOEXCEPT
{ je_free(p
); }
47 } // namespace rocksdb
49 void* operator new(size_t size
) {
50 void* p
= je_malloc(size
);
52 throw std::bad_alloc();
57 void* operator new[](size_t size
) {
58 void* p
= je_malloc(size
);
60 throw std::bad_alloc();
65 void operator delete(void* p
) {
71 void operator delete[](void* p
) {