Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::pmr::polymorphic_allocator<T>::allocate_object

      From cppreference.com
      <cpp‎ |memory‎ |polymorphic allocator
       
       
      Memory management library
      (exposition only*)
      Allocators
      Uninitialized memory algorithms
      Constrained uninitialized memory algorithms
      Memory resources
      Uninitialized storage(until C++20)
      (until C++20*)
      (until C++20*)
      Garbage collector support(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
      (C++11)(until C++23)
       
       
      template<class U>
      U* allocate_object(std::size_t n=1);
      (since C++20)

      Allocates storage forn objects of typeU using the underlying memory resource.

      Ifstd::numeric_limits<std::size_t>::max()/ sizeof(U)< n, throwsstd::bad_array_new_length, otherwise equivalent toreturnstatic_cast<U*>(allocate_bytes(n* sizeof(U), alignof(U)));.

      Contents

      [edit]Parameters

      n - the number of objects to allocate storage for

      [edit]Return value

      A pointer to the allocated storage.

      [edit]Notes

      This function was introduced for use with the fully-specialized allocatorstd::pmr::polymorphic_allocator<>, but it may be useful in any specialization as a shortcut to avoid having to rebind fromstd::pmr::polymorphic_allocator<T> tostd::pmr::polymorphic_allocator<U>.

      SinceU is not deduced, it must be provided as a template argument when calling this function.

      [edit]Exceptions

      Throwsstd::bad_array_new_length ifn>std::numeric_limits<std::size_t>::max()/ sizeof(U); may also be any exceptions thrown by the call toresource()->allocate.

      [edit]See also

      allocate raw aligned memory from the underlying resource
      (public member function)[edit]
      (C++20)
      allocates and constructs an object
      (public member function)[edit]
      allocate memory
      (public member function)[edit]
      [static]
      allocates uninitialized storage using the allocator
      (public static member function ofstd::allocator_traits<Alloc>)[edit]
      allocates memory
      (public member function ofstd::pmr::memory_resource)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/polymorphic_allocator/allocate_object&oldid=173021"

      [8]ページ先頭

      ©2009-2025 Movatter.jp