MySQL 9.1.0
Source Code Documentation
service_thd_alloc.h File Reference

This service provides functions to allocate memory in a connection local memory pool. More...

#include <stdlib.h>
#include <mysql/mysql_lex_string.h>

Go to the source code of this file.

Classes

struct  thd_alloc_service_st
 

Macros

#define MYSQL_THD   THD *
 
#define MYSQL_SERVICE_THD_ALLOC_INCLUDED
 

Functions

void * thd_alloc (MYSQL_THD thd, size_t size)
 Allocate memory in the connection's local memory pool. More...
 
void * thd_calloc (MYSQL_THD thd, size_t size)
 
char * thd_strdup (MYSQL_THD thd, const char *str)
 
char * thd_strmake (MYSQL_THD thd, const char *str, size_t size)
 
void * thd_memdup (MYSQL_THD thd, const void *str, size_t size)
 
MYSQL_LEX_STRINGthd_make_lex_string (MYSQL_THD thd, MYSQL_LEX_STRING *lex_str, const char *str, size_t size, int allocate_lex_string)
 Create a LEX_STRING in this connection's local memory pool. More...
 

Variables

struct thd_alloc_service_stthd_alloc_service
 

Detailed Description

This service provides functions to allocate memory in a connection local memory pool.

The memory allocated there will be automatically freed at the end of the statement, don't use it for allocations that should live longer than that. For short living allocations this is more efficient than using my_malloc and friends, and automatic "garbage collection" allows not to think about memory leaks.

The pool is best for small to medium objects, don't use it for large allocations - they are better served with my_malloc.

Macro Definition Documentation

◆ MYSQL_SERVICE_THD_ALLOC_INCLUDED

#define MYSQL_SERVICE_THD_ALLOC_INCLUDED

◆ MYSQL_THD

#define MYSQL_THD   THD *

Function Documentation

◆ thd_alloc()

void * thd_alloc ( MYSQL_THD  thd,
size_t  size 
)

Allocate memory in the connection's local memory pool.

When properly used in place of my_malloc(), this can significantly improve concurrency. Don't use this or related functions to allocate large chunks of memory. Use for temporary storage only. The memory will be freed automatically at the end of the statement; no explicit code is required to prevent memory leaks.

See also
alloc_root()

◆ thd_calloc()

void * thd_calloc ( MYSQL_THD  thd,
size_t  size 
)
See also
thd_alloc()

◆ thd_make_lex_string()

MYSQL_LEX_STRING * thd_make_lex_string ( MYSQL_THD  thd,
MYSQL_LEX_STRING lex_str,
const char *  str,
size_t  size,
int  allocate_lex_string 
)

Create a LEX_STRING in this connection's local memory pool.

Parameters
thduser thread connection handle
lex_strpointer to LEX_STRING object to be initialized
strinitializer to be copied into lex_str
sizelength of str, in bytes
allocate_lex_stringflag: if TRUE, allocate new LEX_STRING object, instead of using lex_str value
Returns
NULL on failure, or pointer to the LEX_STRING object
See also
thd_alloc()

◆ thd_memdup()

void * thd_memdup ( MYSQL_THD  thd,
const void *  str,
size_t  size 
)
See also
thd_alloc()

◆ thd_strdup()

char * thd_strdup ( MYSQL_THD  thd,
const char *  str 
)
See also
thd_alloc()

◆ thd_strmake()

char * thd_strmake ( MYSQL_THD  thd,
const char *  str,
size_t  size 
)
See also
thd_alloc()

Variable Documentation

◆ thd_alloc_service

struct thd_alloc_service_st * thd_alloc_service