MySQL 9.1.0
Source Code Documentation
my_alloc.h File Reference

This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical reasons). More...

#include <string.h>
#include <memory>
#include <new>
#include <type_traits>
#include <utility>
#include "memory_debugging.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_pointer_arithmetic.h"
#include "mysql/psi/psi_memory.h"

Go to the source code of this file.

Classes

struct  MEM_ROOT
 The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks. More...
 
struct  MEM_ROOT::Block
 
class  Destroy_only< T >
 

Typedefs

template<class T >
using unique_ptr_destroy_only = std::unique_ptr< T, Destroy_only< T > >
 std::unique_ptr, but only destroying. More...
 

Functions

void sql_alloc_error_handler ()
 
void * operator new (size_t size, MEM_ROOT *mem_root, const std::nothrow_t &arg=std::nothrow) noexcept
 Allocate an object of the given type. More...
 
void * operator new[] (size_t size, MEM_ROOT *mem_root, const std::nothrow_t &arg=std::nothrow) noexcept
 
void operator delete (void *, MEM_ROOT *, const std::nothrow_t &) noexcept
 
void operator delete[] (void *, MEM_ROOT *, const std::nothrow_t &) noexcept
 
template<class T >
void destroy_at (T *ptr)
 
template<typename T , typename... Args>
unique_ptr_destroy_only< T > make_unique_destroy_only (MEM_ROOT *mem_root, Args &&...args)
 

Detailed Description

This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical reasons).

Typedef Documentation

◆ unique_ptr_destroy_only

template<class T >
using unique_ptr_destroy_only = std::unique_ptr<T, Destroy_only<T> >

std::unique_ptr, but only destroying.

Function Documentation

◆ destroy_at()

template<class T >
void destroy_at ( T *  ptr)
inline

◆ make_unique_destroy_only()

template<typename T , typename... Args>
unique_ptr_destroy_only< T > make_unique_destroy_only ( MEM_ROOT mem_root,
Args &&...  args 
)

◆ operator delete()

void operator delete ( void *  ,
MEM_ROOT ,
const std::nothrow_t &   
)
inlinenoexcept

◆ operator delete[]()

void operator delete[] ( void *  ,
MEM_ROOT ,
const std::nothrow_t &   
)
inlinenoexcept

◆ operator new()

void * operator new ( size_t  size,
MEM_ROOT mem_root,
const std::nothrow_t &  arg = std::nothrow 
)
inlinenoexcept

Allocate an object of the given type.

Use like this:

Foo *foo = new (mem_root) Foo();

Note that unlike regular operator new, this will not throw exceptions. However, it can return nullptr if the capacity of the MEM_ROOT has been reached. This is allowed since it is not a replacement for global operator new, and thus isn't used automatically by e.g. standard library containers.

TODO: This syntax is confusing in that it could look like allocating a MEM_ROOT using regular placement new. We should make a less ambiguous syntax, e.g. new (On(mem_root)) Foo().

◆ operator new[]()

void * operator new[] ( size_t  size,
MEM_ROOT mem_root,
const std::nothrow_t &  arg = std::nothrow 
)
inlinenoexcept

◆ sql_alloc_error_handler()

void sql_alloc_error_handler ( )