File: allocator.yo

package info (click to toggle)
c%2B%2B-annotations 12.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,044 kB
  • sloc: cpp: 24,337; makefile: 1,517; ansic: 165; sh: 121; perl: 90
file content (29 lines) | stat: -rw-r--r-- 1,510 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Most containers use a special object for allocating the memory that is managed
by them. This object is called an i(allocator), and it's type is (usually by
default) specified when a container is constructed. A container's allocator
can be obtained using the container's tt(get_allocator) member, which returns
a copy of the allocator used by the container. Allocators offer the following
members:
    itemization(
    itht(address)(value_type *address(value_type &object))
        quote(returns the address of tt(object).)
    itht(allocate)(value_type *allocate(size_t count))
        quote(allocates raw memory for holding tt(count) values of the
container's tt(value_type).)
    itht(construct)(void construct(value_type *object, Arg &&...args))
        quote(using placement new, uses the arguments following tt(object) to
install a value at tt(object).)
    itht(destroy)(void destroy(value_type *object))
        quote(calls tt(object)'s destructor (but doesn't deallocate
tt(object)'s own memory).)
    itht(deallocate member)(void deallocate(value_type *object, size_t count))
        quote(calls tt(operator delete) to delete object's memory, previously
allocated by tt(allocate).)
    itht(max_size)(size_t max_size())
        quote(returns the maximum number of elements that tt(allocate) can
allocate.)
    )

    Here is an example, using the allocator of a vector of strings (see
section ref(VECTOR) below for a description of the tt(vector) container):
    verbinclude(-a examples/allocator.cc)