MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
service_thd_alloc.h File Reference
#include <stdlib.h>
Include dependency graph for service_thd_alloc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  st_mysql_lex_string
struct  thd_alloc_service_st

Typedefs

typedef struct st_mysql_lex_string MYSQL_LEX_STRING

Functions

void * thd_alloc (MYSQL_THD thd, unsigned int size)
void * thd_calloc (MYSQL_THD thd, unsigned int size)
char * thd_strdup (MYSQL_THD thd, const char *str)
char * thd_strmake (MYSQL_THD thd, const char *str, unsigned int size)
void * thd_memdup (MYSQL_THD thd, const void *str, unsigned int size)
MYSQL_LEX_STRINGthd_make_lex_string (MYSQL_THD thd, MYSQL_LEX_STRING *lex_str, const char *str, unsigned int size, int allocate_lex_string)

Variables

struct thd_alloc_service_stthd_alloc_service

Detailed Description

This service provdes 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.

Definition in file service_thd_alloc.h.

Function Documentation

void* thd_alloc ( MYSQL_THD  thd,
unsigned int  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()

Definition at line 1301 of file sql_class.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

void* thd_calloc ( MYSQL_THD  thd,
unsigned int  size 
)
See Also
thd_alloc()

Definition at line 1307 of file sql_class.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

MYSQL_LEX_STRING* thd_make_lex_string ( MYSQL_THD  thd,
MYSQL_LEX_STRING lex_str,
const char *  str,
unsigned int  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()
void* thd_memdup ( MYSQL_THD  thd,
const void *  str,
unsigned int  size 
)
See Also
thd_alloc()

Definition at line 1334 of file sql_class.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1313 of file sql_class.cc.

Here is the call graph for this function:

Here is the caller graph for this function:

char* thd_strmake ( MYSQL_THD  thd,
const char *  str,
unsigned int  size 
)
See Also
thd_alloc()

Definition at line 1319 of file sql_class.cc.

Here is the call graph for this function:

Here is the caller graph for this function: