MySQL 8.4.0
Source Code Documentation
service_mysql_alloc.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_SERVICE_MYSQL_ALLOC_INCLUDED
25#define MYSQL_SERVICE_MYSQL_ALLOC_INCLUDED
26
27/**
28 @file include/mysql/service_mysql_alloc.h
29*/
30
31#ifndef MYSQL_ABI_CHECK
32#include <stdlib.h>
33#endif
34
35/* PSI_memory_key */
37
38/* myf */
39typedef int myf_t;
40
41typedef void *(*mysql_malloc_t)(PSI_memory_key key, size_t size, myf_t flags);
42typedef void *(*mysql_realloc_t)(PSI_memory_key key, void *ptr, size_t size,
43 myf_t flags);
44typedef void (*mysql_claim_t)(const void *ptr, bool claim);
45typedef void (*mysql_free_t)(void *ptr);
46typedef void *(*my_memdup_t)(PSI_memory_key key, const void *from,
47 size_t length, myf_t flags);
48typedef char *(*my_strdup_t)(PSI_memory_key key, const char *from, myf_t flags);
49typedef char *(*my_strndup_t)(PSI_memory_key key, const char *from,
50 size_t length, myf_t flags);
51
52/**
53 @ingroup group_ext_plugin_services
54
55 This service allows plugins to allocate and free memory through the server's
56 memory handling routines.
57 This allows uniform memory handling and instrumentation.
58*/
60 /**
61 Allocates a block of memory
62
63 @sa my_malloc
64 */
66 /**
67 Reallocates a block of memory
68
69 @sa my_realloc
70 */
72 /**
73 Re-instruments a block of memory
74
75 @sa my_claim
76 */
78 /**
79 Frees a block of memory
80
81 @sa my_free
82 */
84 /**
85 Copies a buffer into a new buffer
86
87 @sa my_memdup
88 */
90 /**
91 Copies a string into a new buffer
92
93 @sa my_strdup
94 */
96 /**
97 Copies no more than n characters of a string into a new buffer
98
99 @sa my_strndup
100 */
102};
103
105
106#ifdef MYSQL_DYNAMIC_PLUGIN
107
108#define my_malloc mysql_malloc_service->mysql_malloc
109#define my_realloc mysql_malloc_service->mysql_realloc
110#define my_claim mysql_malloc_service->mysql_claim
111#define my_free mysql_malloc_service->mysql_free
112#define my_memdup mysql_malloc_service->my_memdup
113#define my_strdup mysql_malloc_service->my_strdup
114#define my_strndup mysql_malloc_service->my_strndup
115
116#else
117
118extern void *my_malloc(PSI_memory_key key, size_t size, myf_t flags);
119extern void *my_realloc(PSI_memory_key key, void *ptr, size_t size,
120 myf_t flags);
121extern void my_claim(const void *ptr, bool claim);
122extern void my_free(void *ptr);
123extern void *my_memdup(PSI_memory_key key, const void *from, size_t length,
124 myf_t flags);
125extern char *my_strdup(PSI_memory_key key, const char *from, myf_t flags);
126extern char *my_strndup(PSI_memory_key key, const char *from, size_t length,
127 myf_t flags);
128
129#ifdef _WIN32
130extern void *my_std_malloc(PSI_memory_key key, size_t size, myf_t flags);
131extern void *my_std_realloc(PSI_memory_key key, void *ptr, size_t size,
132 myf_t flags);
133extern void my_std_free(void *ptr);
134
135#endif // _WIN32
136
137#endif
138
139#endif
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
static int flags[50]
Definition: hp_test1.cc:40
void * my_std_malloc(PSI_memory_key key, size_t size, myf flags)
Definition: my_malloc.cc:390
void my_std_free(void *ptr)
Definition: my_malloc.cc:471
void * my_std_realloc(PSI_memory_key key, void *ptr, size_t size, myf flags)
Definition: my_malloc.cc:454
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
size_t size(const char *const c)
Definition: base64.h:46
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
char *(* my_strdup_t)(PSI_memory_key key, const char *from, myf_t flags)
Definition: service_mysql_alloc.h:48
char * my_strdup(PSI_memory_key key, const char *from, myf_t flags)
Definition: my_malloc.cc:548
void * my_memdup(PSI_memory_key key, const void *from, size_t length, myf_t flags)
Definition: my_malloc.cc:540
void my_free(void *ptr)
Frees the memory pointed by the ptr.
Definition: my_memory.cc:81
void(* mysql_free_t)(void *ptr)
Definition: service_mysql_alloc.h:45
struct mysql_malloc_service_st * mysql_malloc_service
Definition: service_mysql_alloc.h:104
void(* mysql_claim_t)(const void *ptr, bool claim)
Definition: service_mysql_alloc.h:44
void *(* mysql_malloc_t)(PSI_memory_key key, size_t size, myf_t flags)
Definition: service_mysql_alloc.h:41
void * my_malloc(PSI_memory_key key, size_t size, myf_t flags)
Allocates size bytes of memory.
Definition: my_memory.cc:57
void my_claim(const void *ptr, bool claim)
Definition: my_malloc.cc:458
int myf_t
Definition: service_mysql_alloc.h:39
void *(* mysql_realloc_t)(PSI_memory_key key, void *ptr, size_t size, myf_t flags)
Definition: service_mysql_alloc.h:42
char * my_strndup(PSI_memory_key key, const char *from, size_t length, myf_t flags)
Definition: my_malloc.cc:556
void *(* my_memdup_t)(PSI_memory_key key, const void *from, size_t length, myf_t flags)
Definition: service_mysql_alloc.h:46
char *(* my_strndup_t)(PSI_memory_key key, const char *from, size_t length, myf_t flags)
Definition: service_mysql_alloc.h:49
void * my_realloc(PSI_memory_key key, void *ptr, size_t size, myf_t flags)
Definition: my_malloc.cc:449
This service allows plugins to allocate and free memory through the server's memory handling routines...
Definition: service_mysql_alloc.h:59
mysql_realloc_t mysql_realloc
Reallocates a block of memory.
Definition: service_mysql_alloc.h:71
my_memdup_t my_memdup
Copies a buffer into a new buffer.
Definition: service_mysql_alloc.h:89
my_strndup_t my_strndup
Copies no more than n characters of a string into a new buffer.
Definition: service_mysql_alloc.h:101
my_strdup_t my_strdup
Copies a string into a new buffer.
Definition: service_mysql_alloc.h:95
mysql_free_t mysql_free
Frees a block of memory.
Definition: service_mysql_alloc.h:83
mysql_malloc_t mysql_malloc
Allocates a block of memory.
Definition: service_mysql_alloc.h:65
mysql_claim_t mysql_claim
Re-instruments a block of memory.
Definition: service_mysql_alloc.h:77