34#ifndef MYSQL_BUFFER_MANAGED_BUFFER_H_
35#define MYSQL_BUFFER_MANAGED_BUFFER_H_
110template <
class Char_tp =
unsigned char>
177 bool delete_default_buffer =
180 if (delete_default_buffer)
209 auto [
error, new_capacity] =
252 if (requested_write_size > std::numeric_limits<Size_t>::max() - read_size)
308 }
catch (std::bad_alloc &) {
320 assert(new_buffer != this->
read_part().data());
323 auto read_size =
r.size();
324 if (read_size) memcpy(new_buffer,
r.begin(), read_size);
328 w =
Buffer_view_t(new_buffer + read_size, new_size - read_size);
348 std::size_t(8 * 1024);
356template <
class Char_t =
unsigned char,
357 std::size_t preallocated_size =
Iterator_t begin()
Return pointer to the first character of the data.
Definition: buffer_view.h:94
Size_t size() const
Return the number of bytes.
Definition: buffer_view.h:112
Description of a heuristic to determine how much memory to allocate.
Definition: grow_calculator.h:67
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:111
Managed_buffer & operator=(Managed_buffer &&other) noexcept=default
Managed_buffer(Managed_buffer &other)=delete
Char_t * allocate_buffer(Size_t new_size)
Allocate a new buffer and return it.
Definition: managed_buffer.h:305
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:161
Char_tp Char_t
Definition: managed_buffer.h:113
Grow_calculator_t m_grow_calculator
Calculator for growing the buffer.
Definition: managed_buffer.h:332
void replace_buffer(Char_t *new_buffer, Size_t new_size)
Replace the underlying data buffer by the given one.
Definition: managed_buffer.h:319
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:206
void reset()
Reset the buffer.
Definition: managed_buffer.h:262
const Grow_calculator_t & get_grow_calculator() const
Return a const reference to the grow calculator.
Definition: managed_buffer.h:290
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:144
Size_t get_default_capacity()
Return the size of the default buffer.
Definition: managed_buffer.h:295
Char_t * m_default_buffer
User-provided, user-owned buffer.
Definition: managed_buffer.h:338
Char_allocator_t m_char_allocator
Allocator to grow the buffer.
Definition: managed_buffer.h:335
Managed_buffer(const Memory_resource_t &memory_resource=Memory_resource_t())
Construct a new object without a default buffer.
Definition: managed_buffer.h:130
bool m_owns_default_buffer
If true, the default buffer will be deallocated by the destructor.
Definition: managed_buffer.h:344
mysqlns::resource::Memory_resource Memory_resource_t
Definition: managed_buffer.h:121
Size_t m_default_capacity
Size of user-provided, user-owned buffer.
Definition: managed_buffer.h:341
std::size_t Size_t
Definition: rw_buffer.h:63
Managed_buffer(Managed_buffer &&other) noexcept=default
void set_grow_calculator(const Grow_calculator_t &grow_calculator)
Set the grow calculator.
Definition: managed_buffer.h:285
~Managed_buffer() override
Definition: managed_buffer.h:175
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:250
Buffer_view< Char_t > Buffer_view_t
Definition: managed_buffer.h:114
Managed_buffer & operator=(Managed_buffer &other)=delete
Definition: managed_buffer.h:359
Preallocated_managed_buffer(const Memory_resource_t &memory_resource=Memory_resource_t())
Definition: managed_buffer.h:365
Char_t m_preallocated_buffer[preallocated_size==0 ? 1 :preallocated_size]
Preallocated buffer.
Definition: managed_buffer.h:373
Non-owning read/write memory buffer manager with a fixed size.
Definition: rw_buffer.h:60
const Char_t * Const_iterator_t
Definition: rw_buffer.h:66
Char_t * Iterator_t
Definition: rw_buffer.h:65
const Buffer_view_t & read_part() const
Return the read part.
Definition: rw_buffer.h:95
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 & write_part() const
Return the write part.
Definition: rw_buffer.h:101
std::size_t Size_t
Definition: rw_buffer.h:63
constexpr T * allocate(size_type n)
Use the Memory_resource to allocate the given number of elements of type T.
Definition: allocator.h:84
constexpr void deallocate(T *p, size_type size)
Use the Memory_resource to deallocate the given pointer.
Definition: allocator.h:95
Polymorphism-free memory resource class with custom allocator and deallocator functions.
Definition: memory_resource.h:88
Fido Client Authentication nullptr
Definition: fido_client_plugin.cc:222
Allocator class that uses a polymorphic Memory_resource to allocate memory.
Class that wraps resources in a polymorphic manner.
Definition: buffer_sequence_view.h:51
Grow_status
Error statuses for classes that use Grow_calculator.
Definition: grow_status.h:37
@ 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.
constexpr std::size_t default_preallocated_managed_buffer_size
Definition: managed_buffer.h:347
#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:66