C++ Container

Containers in #202202241717 are continuous memory structures that adhere to 202202012306 principle. They possess the ownership of their own objects.

They can be categorised into 3 types:

  • sequence, like array, list, forward_list, deque and vector
  • associative, like map and set, which is built using binary search tree
  • unordered associative, like unordered_map and unordered_set, which is built using hash table

Most of them are iteratable and can be deduced from their built-in 202204182011. The iterator then can iterate through first to last.

Standard libraries’ containers usually define value_type and iterator to indicate what type of the value and iterator are stored or used in them. It is advised to follow this convention if a custom container should be used. This could be useful if 202204181536 should be used in the codebase although in C++20, 202203281200 is the better alternative for it.

The default 202205161742# for containers are new and delete. You could change it in order to optimise the memory usage.

Links to this page
  • Span

    gsl::span or in C++20 std::span is an object that hold a contiguous sequence of objects which provide a range checking for primitive arrays that is not one of the #202202241719. It provides a range checking for them where the size of the sequence is to be known at compile time. It deprecates the use of either raw pointer or smart pointer in order to obtain a view on a sequence of objects.

  • Lateral Propagation

    Lateral Propagation is an allocation strategy that focus on what happens in the #202202241719’s #202205161742 during copy/move construction, copy/move assignment and swap.

  • Iterator

    Iterator in #202202241717 could be used to iterate through 202202241719 or structures. They do not own the object that they refer.

    Multi-pass Iterator could be iterated more than one time and its content will not be altered when wrote or read (using dereference). The example of such are forward iterator, bidirectional iterator and random access iterator. Most sequence 202202241719 support this.

  • C++ Standard Template Library (STL)
  • C++ Allocator

    C++ Allocator is a class that dictate memory management and address model of #202202241719. We can create an allocator for various memory allocation policy such as stack allocation, per-thread allocation and Arena Allocation.

    Modern C++(14 and 17) introduce the polymorphic memory resources (std::pmr) which is not Lateral Propagation. This means that the allocator will be able to stick to the lifetime of the #202202241719. It includes allocators like synchronized_pool_resource, unsynchronized_pool_resource and monotonic_buffer_resource.

#cpp #stl #memory #container