31#ifndef MYSQL_CONTAINERS_BUFFERS_MANAGED_BUFFER_H
32#define MYSQL_CONTAINERS_BUFFERS_MANAGED_BUFFER_H
107template <
class Char_tp =
unsigned char>
174 bool delete_default_buffer =
177 if (delete_default_buffer)
206 auto [
error, new_capacity] =
249 if (requested_write_size > std::numeric_limits<Size_t>::max() - read_size)
305 }
catch (std::bad_alloc &) {
317 assert(new_buffer != this->
read_part().data());
320 auto read_size =
r.size();
321 if (read_size) memcpy(new_buffer,
r.begin(), read_size);
325 w =
Buffer_view_t(new_buffer + read_size, new_size - read_size);
345 std::size_t(8 * 1024);
353template <
class Char_t =
unsigned char,
354 std::size_t preallocated_size =
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
constexpr void deallocate(T *p, size_type size)
Use the Memory_resource to deallocate the given pointer.
Definition: allocator.h:95
constexpr T * allocate(size_type n)
Use the Memory_resource to allocate the given number of elements of type T.
Definition: allocator.h:84
Polymorphism-free memory resource class with custom allocator and deallocator functions.
Definition: memory_resource.h:88
Size_t size() const
Return the number of bytes.
Definition: buffer_view.h:112
Iterator_t begin()
Return pointer to the first character of the data.
Definition: buffer_view.h:94
Description of a heuristic to determine how much memory to allocate.
Definition: grow_calculator.h:68
Result_t compute_new_size(Size_t old_size, Size_t requested_size) const
Compute the new size.
Definition: grow_calculator.cpp:39
Owned, growable, contiguous memory buffer.
Definition: managed_buffer.h:108
void reset()
Reset the buffer.
Definition: managed_buffer.h:259
Managed_buffer(Size_t default_capacity, const Memory_resource_t &memory_resource=Memory_resource_t())
Construct a new object that owns a default buffer.
Definition: managed_buffer.h:141
Managed_buffer(const Memory_resource_t &memory_resource=Memory_resource_t())
Construct a new object without a default buffer.
Definition: managed_buffer.h:127
Char_allocator_t m_char_allocator
Allocator to grow the buffer.
Definition: managed_buffer.h:332
Managed_buffer & operator=(Managed_buffer &other)=delete
void set_grow_calculator(const Grow_calculator_t &grow_calculator)
Set the grow calculator.
Definition: managed_buffer.h:282
mysql::allocators::Memory_resource Memory_resource_t
Definition: managed_buffer.h:118
Managed_buffer & operator=(Managed_buffer &&other) noexcept=default
Managed_buffer(Buffer_view_t default_buffer, const Memory_resource_t &memory_resource=Memory_resource_t())
Construct a new object that uses the given default buffer.
Definition: managed_buffer.h:158
Grow_status reserve_total_size(Size_t requested_size)
Reserve space so that the total buffer size is at least the given number.
Definition: managed_buffer.h:203
Grow_status reserve_write_size(Size_t requested_write_size)
Reserve space so that the write size is at least the given number.
Definition: managed_buffer.h:247
Char_t * m_default_buffer
User-provided, user-owned buffer.
Definition: managed_buffer.h:335
void replace_buffer(Char_t *new_buffer, Size_t new_size)
Replace the underlying data buffer by the given one.
Definition: managed_buffer.h:316
Char_t * allocate_buffer(Size_t new_size)
Allocate a new buffer and return it.
Definition: managed_buffer.h:302
Buffer_view< Char_t > Buffer_view_t
Definition: managed_buffer.h:111
Char_tp Char_t
Definition: managed_buffer.h:110
Managed_buffer(Managed_buffer &other)=delete
bool m_owns_default_buffer
If true, the default buffer will be deallocated by the destructor.
Definition: managed_buffer.h:341
Managed_buffer(Managed_buffer &&other) noexcept=default
std::size_t Size_t
Definition: rw_buffer.h:63
Size_t m_default_capacity
Size of user-provided, user-owned buffer.
Definition: managed_buffer.h:338
const Grow_calculator_t & get_grow_calculator() const
Return a const reference to the grow calculator.
Definition: managed_buffer.h:287
Size_t get_default_capacity()
Return the size of the default buffer.
Definition: managed_buffer.h:292
Grow_calculator_t m_grow_calculator
Calculator for growing the buffer.
Definition: managed_buffer.h:329
~Managed_buffer() override
Definition: managed_buffer.h:172
Definition: managed_buffer.h:356
Char_t m_preallocated_buffer[preallocated_size==0 ? 1 :preallocated_size]
Preallocated buffer.
Definition: managed_buffer.h:370
Preallocated_managed_buffer(const Memory_resource_t &memory_resource=Memory_resource_t())
Definition: managed_buffer.h:362
Non-owning read/write memory buffer manager with a fixed size.
Definition: rw_buffer.h:60
Size_t capacity() const
Return the total size of the read part and the write part.
Definition: rw_buffer.h:107
const Buffer_view_t & read_part() const
Return the read part.
Definition: rw_buffer.h:95
Char_t * Iterator_t
Definition: rw_buffer.h:65
const Buffer_view_t & write_part() const
Return the write part.
Definition: rw_buffer.h:101
const Char_t * Const_iterator_t
Definition: rw_buffer.h:66
std::size_t Size_t
Definition: rw_buffer.h:63
Allocator class that uses a polymorphic Memory_resource to allocate memory.
Class that wraps resources in a polymorphic manner.
void error(const char *format,...)
Definition: buffer_sequence_view.h:51
constexpr std::size_t default_preallocated_managed_buffer_size
Definition: managed_buffer.h:344
Grow_status
Error statuses for classes that use Grow_calculator.
Definition: grow_status.h:38
@ exceeds_max_size
A grow operation could not be performed because there is a configured maximum size.
@ success
A grow operation succeeded.
@ out_of_memory
A grow operation failed because memory allocation failed.
const char * begin(const char *const c)
Definition: base64.h:44
size_t size(const char *const c)
Definition: base64.h:46
#define NODISCARD
The function attribute [[NODISCARD]] is a replacement for [[nodiscard]] to workaround a gcc bug.
Definition: nodiscard.h:47
const mysql_service_registry_t * r
Definition: pfs_example_plugin_employee.cc:86
Non-owning manager for a fixed memory buffer, which is split into a read part and a write part,...
Contains wrapper functions for memory allocation and deallocation.
#define BAPI_TRACE
Definition: wrapper_functions.h:65