/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// Implement the set of alignment functions in terms of memalign. template <void* (*memalign)(size_t, size_t)> struct AlignedAllocator { staticinlineint posix_memalign(void** aMemPtr, size_t aAlignment,
size_t aSize) { void* result;
// alignment must be a power of two and a multiple of sizeof(void*) if (((aAlignment - 1) & aAlignment) != 0 || aAlignment < sizeof(void*)) { return EINVAL;
}
// The 0-->1 size promotion is done in the memalign() call below
result = memalign(aAlignment, aSize);
// These classes each implement the same interface. Writing out the // interface for each one rather than using inheritance makes things more // explicit. // // Note: compilers are expected to be able to optimize out `this`.
// The MozJemalloc allocator struct MozJemalloc { # define MALLOC_DECL(name, return_type, ...) \ staticinline return_type name(__VA_ARGS__); # include "malloc_decls.h"
};
# ifdef MOZ_PHC using CanonicalMalloc = MozJemallocPHC; # else using CanonicalMalloc = MozJemalloc; # endif
# ifdef MOZ_REPLACE_MALLOC using DefaultMalloc = ReplaceMalloc; # else using DefaultMalloc = CanonicalMalloc; # endif
// Poison - write "poison" to cells upon deallocation.
constexpr uint8_t kAllocPoison = 0xe5;
// Junk - write this junk value to freshly allocated cells.
constexpr uint8_t kAllocJunk = 0xe4;
// Maximum size of L1 cache line. This is used to avoid cache line aliasing, // so over-estimates are okay (up to a point), but under-estimates will // negatively affect performance.
constexpr size_t kCacheLineSize = # ifdefined(XP_DARWIN) && defined(__aarch64__)
128 # else
64 # endif
;
#endif// MOZ_MEMORY
// Dummy implementation of the moz_arena_* API, falling back to a given // implementation of the base allocator. template <typename T> struct DummyArenaAllocator { static arena_id_t moz_create_arena_with_params(arena_params_t*) { return 0; }
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.