1*38fd1498Szrj// <memory> -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj// Copyright (C) 2001-2018 Free Software Foundation, Inc. 4*38fd1498Szrj// 5*38fd1498Szrj// This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj// software; you can redistribute it and/or modify it under the 7*38fd1498Szrj// terms of the GNU General Public License as published by the 8*38fd1498Szrj// Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj// any later version. 10*38fd1498Szrj 11*38fd1498Szrj// This library is distributed in the hope that it will be useful, 12*38fd1498Szrj// but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj// GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj// Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj// permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj// 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj// You should have received a copy of the GNU General Public License and 21*38fd1498Szrj// a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj// <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj/* 26*38fd1498Szrj * Copyright (c) 1997-1999 27*38fd1498Szrj * Silicon Graphics Computer Systems, Inc. 28*38fd1498Szrj * 29*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 30*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 31*38fd1498Szrj * provided that the above copyright notice appear in all copies and 32*38fd1498Szrj * that both that copyright notice and this permission notice appear 33*38fd1498Szrj * in supporting documentation. Silicon Graphics makes no 34*38fd1498Szrj * representations about the suitability of this software for any 35*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 36*38fd1498Szrj * 37*38fd1498Szrj */ 38*38fd1498Szrj 39*38fd1498Szrj/** @file include/memory 40*38fd1498Szrj * This is a Standard C++ Library header. 41*38fd1498Szrj */ 42*38fd1498Szrj 43*38fd1498Szrj#ifndef _GLIBCXX_MEMORY 44*38fd1498Szrj#define _GLIBCXX_MEMORY 1 45*38fd1498Szrj 46*38fd1498Szrj#pragma GCC system_header 47*38fd1498Szrj 48*38fd1498Szrj/** 49*38fd1498Szrj * @defgroup memory Memory 50*38fd1498Szrj * @ingroup utilities 51*38fd1498Szrj * 52*38fd1498Szrj * Components for memory allocation, deallocation, and management. 53*38fd1498Szrj */ 54*38fd1498Szrj 55*38fd1498Szrj/** 56*38fd1498Szrj * @defgroup pointer_abstractions Pointer Abstractions 57*38fd1498Szrj * @ingroup memory 58*38fd1498Szrj * 59*38fd1498Szrj * Smart pointers, etc. 60*38fd1498Szrj */ 61*38fd1498Szrj 62*38fd1498Szrj#include <bits/stl_algobase.h> 63*38fd1498Szrj#include <bits/allocator.h> 64*38fd1498Szrj#include <bits/stl_construct.h> 65*38fd1498Szrj#include <bits/stl_uninitialized.h> 66*38fd1498Szrj#include <bits/stl_tempbuf.h> 67*38fd1498Szrj#include <bits/stl_raw_storage_iter.h> 68*38fd1498Szrj 69*38fd1498Szrj#if __cplusplus >= 201103L 70*38fd1498Szrj# include <exception> // std::exception 71*38fd1498Szrj# include <typeinfo> // std::type_info in get_deleter 72*38fd1498Szrj# include <iosfwd> // std::basic_ostream 73*38fd1498Szrj# include <ext/atomicity.h> 74*38fd1498Szrj# include <ext/concurrence.h> 75*38fd1498Szrj# include <bits/functexcept.h> 76*38fd1498Szrj# include <bits/stl_function.h> // std::less 77*38fd1498Szrj# include <bits/uses_allocator.h> 78*38fd1498Szrj# include <type_traits> 79*38fd1498Szrj# include <debug/debug.h> 80*38fd1498Szrj# include <bits/unique_ptr.h> 81*38fd1498Szrj# include <bits/shared_ptr.h> 82*38fd1498Szrj# include <bits/shared_ptr_atomic.h> 83*38fd1498Szrj# if _GLIBCXX_USE_DEPRECATED 84*38fd1498Szrj# include <backward/auto_ptr.h> 85*38fd1498Szrj# endif 86*38fd1498Szrj#else 87*38fd1498Szrj# include <backward/auto_ptr.h> 88*38fd1498Szrj#endif 89*38fd1498Szrj 90*38fd1498Szrj#if __cplusplus >= 201103L 91*38fd1498Szrj# include <cstdint> 92*38fd1498Szrj# ifdef _GLIBCXX_USE_C99_STDINT_TR1 93*38fd1498Szrjnamespace std _GLIBCXX_VISIBILITY(default) 94*38fd1498Szrj{ 95*38fd1498Szrj_GLIBCXX_BEGIN_NAMESPACE_VERSION 96*38fd1498Szrj 97*38fd1498Szrj/** 98*38fd1498Szrj * @brief Fit aligned storage in buffer. 99*38fd1498Szrj * 100*38fd1498Szrj * [ptr.align] 101*38fd1498Szrj * 102*38fd1498Szrj * This function tries to fit @a __size bytes of storage with alignment 103*38fd1498Szrj * @a __align into the buffer @a __ptr of size @a __space bytes. If such 104*38fd1498Szrj * a buffer fits then @a __ptr is changed to point to the first byte of the 105*38fd1498Szrj * aligned storage and @a __space is reduced by the bytes used for alignment. 106*38fd1498Szrj * 107*38fd1498Szrj * @param __align A fundamental or extended alignment value. 108*38fd1498Szrj * @param __size Size of the aligned storage required. 109*38fd1498Szrj * @param __ptr Pointer to a buffer of @a __space bytes. 110*38fd1498Szrj * @param __space Size of the buffer pointed to by @a __ptr. 111*38fd1498Szrj * @return the updated pointer if the aligned storage fits, otherwise nullptr. 112*38fd1498Szrj */ 113*38fd1498Szrjinline void* 114*38fd1498Szrjalign(size_t __align, size_t __size, void*& __ptr, size_t& __space) noexcept 115*38fd1498Szrj{ 116*38fd1498Szrj const auto __intptr = reinterpret_cast<uintptr_t>(__ptr); 117*38fd1498Szrj const auto __aligned = (__intptr - 1u + __align) & -__align; 118*38fd1498Szrj const auto __diff = __aligned - __intptr; 119*38fd1498Szrj if ((__size + __diff) > __space) 120*38fd1498Szrj return nullptr; 121*38fd1498Szrj else 122*38fd1498Szrj { 123*38fd1498Szrj __space -= __diff; 124*38fd1498Szrj return __ptr = reinterpret_cast<void*>(__aligned); 125*38fd1498Szrj } 126*38fd1498Szrj} 127*38fd1498Szrj 128*38fd1498Szrj// 20.7.4 [util.dynamic.safety], pointer safety 129*38fd1498Szrj 130*38fd1498Szrjenum class pointer_safety { relaxed, preferred, strict }; 131*38fd1498Szrj 132*38fd1498Szrjinline void 133*38fd1498Szrjdeclare_reachable(void*) { } 134*38fd1498Szrj 135*38fd1498Szrjtemplate <typename _Tp> 136*38fd1498Szrj inline _Tp* 137*38fd1498Szrj undeclare_reachable(_Tp* __p) { return __p; } 138*38fd1498Szrj 139*38fd1498Szrjinline void 140*38fd1498Szrjdeclare_no_pointers(char*, size_t) { } 141*38fd1498Szrj 142*38fd1498Szrjinline void 143*38fd1498Szrjundeclare_no_pointers(char*, size_t) { } 144*38fd1498Szrj 145*38fd1498Szrjinline pointer_safety 146*38fd1498Szrjget_pointer_safety() noexcept { return pointer_safety::relaxed; } 147*38fd1498Szrj 148*38fd1498Szrj_GLIBCXX_END_NAMESPACE_VERSION 149*38fd1498Szrj} // namespace 150*38fd1498Szrj#endif // _GLIBCXX_USE_C99_STDINT_TR1 151*38fd1498Szrj#endif // C++11 152*38fd1498Szrj 153*38fd1498Szrj#endif /* _GLIBCXX_MEMORY */ 154