31#ifndef MYSQL_BINLOG_EVENT_COMPRESSION_BUFFER_MANAGED_BUFFER_H
32#define MYSQL_BINLOG_EVENT_COMPRESSION_BUFFER_MANAGED_BUFFER_H
108template <
class Char_tp =
unsigned char>
175 bool delete_default_buffer =
178 if (delete_default_buffer)
207 auto [
error, new_capacity] =
250 if (requested_write_size > std::numeric_limits<Size_t>::max() - read_size)
306 }
catch (std::bad_alloc &) {
318 assert(new_buffer != this->
read_part().data());
321 auto read_size =
r.size();
322 if (read_size) memcpy(new_buffer,
r.begin(), read_size);
326 w =
Buffer_view_t(new_buffer + read_size, new_size - read_size);
346 std::size_t(8 * 1024);
354template <
class Char_t =
unsigned char,
355 std::size_t preallocated_size =
Kerberos Client Authentication nullptr
Definition: auth_kerberos_client_plugin.cc:251
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: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:109
Managed_buffer & operator=(Managed_buffer &&other) noexcept=default
~Managed_buffer() override
Definition: managed_buffer.h:173
Grow_calculator_t m_grow_calculator
Calculator for growing the buffer.
Definition: managed_buffer.h:330
Char_tp Char_t
Definition: managed_buffer.h:111
Size_t get_default_capacity()
Return the size of the default buffer.
Definition: managed_buffer.h:293
void reset()
Reset the buffer.
Definition: managed_buffer.h:260
Managed_buffer(Managed_buffer &&other) noexcept=default
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:342
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:248
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:142
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:204
Managed_buffer & operator=(Managed_buffer &other)=delete
Managed_buffer(const Memory_resource_t &memory_resource=Memory_resource_t())
Construct a new object without a default buffer.
Definition: managed_buffer.h:128
mysql::binlog::event::resource::Memory_resource Memory_resource_t
Definition: managed_buffer.h:119
void set_grow_calculator(const Grow_calculator_t &grow_calculator)
Set the grow calculator.
Definition: managed_buffer.h:283
const Grow_calculator_t & get_grow_calculator() const
Return a const reference to the grow calculator.
Definition: managed_buffer.h:288
void replace_buffer(Char_t *new_buffer, Size_t new_size)
Replace the underlying data buffer by the given one.
Definition: managed_buffer.h:317
Char_allocator_t m_char_allocator
Allocator to grow the buffer.
Definition: managed_buffer.h:333
Buffer_view< Char_t > Buffer_view_t
Definition: managed_buffer.h:112
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:159
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:339
Char_t * allocate_buffer(Size_t new_size)
Allocate a new buffer and return it.
Definition: managed_buffer.h:303
Char_t * m_default_buffer
User-provided, user-owned buffer.
Definition: managed_buffer.h:336
Definition: managed_buffer.h:357
Char_t m_preallocated_buffer[preallocated_size==0 ? 1 :preallocated_size]
Preallocated buffer.
Definition: managed_buffer.h:371
Preallocated_managed_buffer(const Memory_resource_t &memory_resource=Memory_resource_t())
Definition: managed_buffer.h:363
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
const Buffer_view_t & read_part() const
Return the read part.
Definition: rw_buffer.h:96
const Buffer_view_t & write_part() const
Return the write part.
Definition: rw_buffer.h:102
std::size_t Size_t
Definition: rw_buffer.h:63
Size_t capacity() const
Return the total size of the read part and the write part.
Definition: rw_buffer.h:108
Char_t * Iterator_t
Definition: rw_buffer.h:65
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
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
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.
constexpr std::size_t default_preallocated_managed_buffer_size
Definition: managed_buffer.h:345
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