Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:34

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___MEMORY_BUILTIN_NEW_ALLOCATOR_H
0010 #define _LIBCPP___CXX03___MEMORY_BUILTIN_NEW_ALLOCATOR_H
0011 
0012 #include <__cxx03/__config>
0013 #include <__cxx03/__memory/unique_ptr.h>
0014 #include <__cxx03/cstddef>
0015 #include <__cxx03/new>
0016 
0017 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0018 #  pragma GCC system_header
0019 #endif
0020 
0021 _LIBCPP_BEGIN_NAMESPACE_STD
0022 
0023 // __builtin_new_allocator -- A non-templated helper for allocating and
0024 // deallocating memory using __builtin_operator_new and
0025 // __builtin_operator_delete. It should be used in preference to
0026 // `std::allocator<T>` to avoid additional instantiations.
0027 struct __builtin_new_allocator {
0028   struct __builtin_new_deleter {
0029     typedef void* pointer_type;
0030 
0031     _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
0032         : __size_(__size), __align_(__align) {}
0033 
0034     _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const _NOEXCEPT {
0035       std::__libcpp_deallocate(__p, __size_, __align_);
0036     }
0037 
0038   private:
0039     size_t __size_;
0040     size_t __align_;
0041   };
0042 
0043   typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
0044 
0045   _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_bytes(size_t __s, size_t __align) {
0046     return __holder_t(std::__libcpp_allocate(__s, __align), __builtin_new_deleter(__s, __align));
0047   }
0048 
0049   _LIBCPP_HIDE_FROM_ABI static void __deallocate_bytes(void* __p, size_t __s, size_t __align) _NOEXCEPT {
0050     std::__libcpp_deallocate(__p, __s, __align);
0051   }
0052 
0053   template <class _Tp>
0054   _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_type(size_t __n) {
0055     return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
0056   }
0057 
0058   template <class _Tp>
0059   _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static void
0060   __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
0061     __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
0062   }
0063 };
0064 
0065 _LIBCPP_END_NAMESPACE_STD
0066 
0067 #endif // _LIBCPP___CXX03___MEMORY_BUILTIN_NEW_ALLOCATOR_H