MySQL  8.0.18
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 "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

static void init_alloc_root (PSI_memory_key key, MEM_ROOT *root, size_t block_size, size_t)
 
void free_root (MEM_ROOT *root, myf flags)
 
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 (T *ptr)
 
template<class T >
void destroy_array (T *ptr, size_t count)
 
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()

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

◆ destroy_array()

template<class T >
void destroy_array ( T *  ptr,
size_t  count 
)
inline

◆ free_root()

void free_root ( MEM_ROOT root,
myf  flags 
)

◆ init_alloc_root()

static void init_alloc_root ( PSI_memory_key  key,
MEM_ROOT root,
size_t  block_size,
size_t   
)
inlinestatic

◆ 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