O'Reilly logo

Understanding MySQL Internals by Sasha Pachev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Utility API Calls

A number of core jobs, such as memory allocation, string operations, or file management, are performed by a group of internal API calls. Due to portability requirements, the standard C library is used very sparingly, and the C++ libraries are not used at all.

There are a large number of utility functions. I cannot cover them all in this book, but I provide a representative sample in Table 3-5.

Table 3-5. Common utility functions

Prototype

Defined in

Description

gptr my_malloc (uint Size, myf MyFlags)

mysys/my_malloc.c

Portability wrapper around malloc ( ). Used for allocating memory blocks for global buffers andother objects that have a lifetime of more than one query, as well as large memory blocks.

void my_free (gptr ptr, myf MyFlags)

mysys/my_malloc.

Frees the blocks allocated with my_malloc( ). Note that my_free( ) has evolved into a macro alias for my_no_flags_free( ), so you should look for the definition of my_no_flags_free( ) rather than my_freel( ) in mysys/my_malloc.c. Nevertheless, my_free ( ) is still what is used throughout the code to free memory blocks.

gptr my multi malloc (myf myFlags, …)

mysys/my_malloc.c

Allocates memory for a set of pointers, and points each to its respective part of one big block. Consider the example:

     char *p1, *p2, *block;
     if (!(block = my_multi_malloc
     (MYF    (MY_WME),
     &p1,10,&p2,20,NULL))
       goto err;

block points to the start of the allocated block, p1 points to a part of it with 10 bytes reserved, and p2 points to another part ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required