Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::allocator_traits<Alloc>::allocate

      From cppreference.com
      <cpp‎ |memory‎ |allocator traits
       
       
      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)
       
       
      Defined in header<memory>
      static pointer allocate( Alloc& a, size_type n);
      (1)(since C++11)
      (constexpr since C++20)
      static pointer allocate( Alloc& a, size_type n, const_void_pointer hint);
      (2)(since C++11)
      (constexpr since C++20)

      Uses the allocatora to allocaten* sizeof(Alloc::value_type) bytes of uninitialized storage. An array of typeAlloc::value_type[n] is created in the storage, but none of its elements are constructed.

      1) Callsa.allocate(n).
      2) Additionally passes memory locality hinthint. Callsa.allocate(n, hint) if possible. If not possible (e.g.a has no two-argument member functionallocate), callsa.allocate(n).

      Contents

      [edit]Parameters

      a - allocator to use
      n - the number of objects to allocate storage for
      hint - pointer to a nearby memory location

      [edit]Return value

      The pointer returned by the call toa.allocate(n).

      [edit]Notes

      Alloc::allocate was not required to create array object untilP0593R6, which made using non-default allocator forstd::vector and some other containers not well-defined according to a strict reading of the core language specification.

      After callingallocate and before construction of elements, pointer arithmetic ofAlloc::value_type* is well-defined within the allocated array, but the behavior is undefined if elements are accessed.

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      allocates uninitialized storage
      (public member function ofstd::allocator<T>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/memory/allocator_traits/allocate&oldid=173086"

      [8]ページ先頭

      ©2009-2025 Movatter.jp