MySQL 9.1.0
Source Code Documentation
|
Utility container class to store elements stably and scalably. More...
#include <inplace_vector.h>
Public Member Functions | |
Inplace_vector (PSI_memory_key psi_key) | |
~Inplace_vector () | |
Release memory space and destroy all contained objects. More... | |
objtype * | get_object (size_t index) |
Get an existing element's pointer, index must be in [0, m_obj_count). More... | |
objtype * | append_object () |
Allocate space for an object, and construct it using its default constructor, and return its address. More... | |
objtype * | push_back (const objtype &obj) |
STL std::vector::push_back interface. More... | |
bool | resize (size_t new_size, const objtype &val=objtype()) |
STL std::vector::resize interface. More... | |
size_t | size () const |
STL std::vector::size interface. More... | |
size_t | capacity () const |
STL std::vector::capacity interface. More... | |
bool | empty () const |
STL std::vector::empty interface. More... | |
void | clear () |
STL std::vector::clear interface. More... | |
const objtype & | back () const |
STL std::vector::back interface. More... | |
objtype & | back () |
STL std::vector::back interface. More... | |
const objtype & | operator[] (size_t i) const |
STL std::vector::operator[] interface. More... | |
objtype & | operator[] (size_t i) |
STL std::vector::operator[] interface. More... | |
void | delete_all_objects () |
Destroy all elements (by calling each element's destructor) stored in the vector, and then release all memory held by it. More... | |
Private Member Functions | |
objtype * | get_space (size_t index) |
Return an existing used slot, or append exactly one slot at end of the last array and return it. More... | |
void | append_new_array () |
Inplace_vector (const Inplace_vector &) | |
Inplace_vector & | operator= (const Inplace_vector &rhs) |
Private Attributes | |
std::vector< objtype * > | m_obj_arrays |
PSI_memory_key | m_psi_key |
size_t | m_obj_count |
bool | m_outof_mem |
Utility container class to store elements stably and scalably.
The address of an element stored in the container is stable as long as the object is alive, no object is copy-constructed/reassigned by push_back operations once it's stored into this container. And users of such containers can* assign to elements stored in the container just like using std::vector.
It is similar to STL vector but it is uniquely suitable in below situation: whenever stable element address, or element copy construction/assignment behaviors are forbidden. It only has a limited subset of the std::vector interface, and especially it doesn't have an iterator interface or element elimination interface, we don't need them for now. And this container is not multi-threading safe. It uses my_malloc/my_free to allocate/free memory arrays and caller can pass PSI key.
The container keeps a collection of arrays, each of which has a fixed NO. of slots to store elements. When one array is full, another is appended. When the vector shrinks at tail, useless arrays are removed and its memory space released.
objtype | The type of the elements to store. |
array_size | The NO. of element slots in each array. |
|
private |
|
inlineexplicit |
|
inline |
Release memory space and destroy all contained objects.
|
inlineprivate |
|
inline |
Allocate space for an object, and construct it using its default constructor, and return its address.
|
inline |
STL std::vector::back interface.
|
inline |
STL std::vector::back interface.
|
inline |
STL std::vector::capacity interface.
|
inline |
STL std::vector::clear interface.
Destroy all elements (by calling each element's destructor) stored in the vector, and then release all memory held by it.
|
inline |
Destroy all elements (by calling each element's destructor) stored in the vector, and then release all memory held by it.
|
inline |
STL std::vector::empty interface.
|
inline |
Get an existing element's pointer, index must be in [0, m_obj_count).
index | The index of the element to return. It must be within valid in-use range of the vector. |
|
inlineprivate |
Return an existing used slot, or append exactly one slot at end of the last array and return it.
If the last array is already full before the append, allocate a new array then allocate one slot and return it.
index | The index of the element slot to return. It must be one within valid in-use range of the vector, or be equal to the size of the vector. |
|
private |
|
inline |
STL std::vector::operator[] interface.
i | The index of the element to return. It must be within valid in-use range of the vector. |
|
inline |
STL std::vector::operator[] interface.
i | The index of the element to return. It must be within valid in-use range of the vector. |
|
inline |
STL std::vector::push_back interface.
It's guaranteed that existing elements stored in the vector is never copy constructed/reassigned by this operation. When the last element array is full, a new one is allocated and tracked.
obj | The element to store into the vector. |
|
inline |
STL std::vector::resize interface.
Has identical behavior as STL std::vector::resize except that no element copy construction or reassignment is ever caused by this operation.
new_size | New size of vector. If smaller than current size, objects at the tail are removed and destroyed. If greater, new objects are added with default value. |
val | default value assigned to extended slots in the vector. Unused if the vector is shrunk. |
|
inline |
STL std::vector::size interface.
|
private |
|
private |
|
private |
|
private |