MySQL 8.1.0
Source Code Documentation
my_aligned_malloc.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef __MY_ALIGNED_MALLOC_H__
24#define __MY_ALIGNED_MALLOC_H__
25
26#include <cstddef>
27
28/**
29 Function allocates size bytes and returns a pointer to the allocated memory.
30 Size and alignment parameters depend on platform on which the function is
31 executed. Please check posix_memalign, memalign and _aligned_malloc functions
32 for details. To conform with all platforms size should be multiple of aligment
33 and aligment should be power of two.
34
35 We can use C++17 aligned new/aligned delete on non-windows platforms once the
36 minimum supported version of tcmalloc becomes >= 2.6.2. Right now TC malloc
37 crashes.
38
39 @param[in] size Multiple of alignment.
40 @param[in] alignment Memory aligment, which must be power of two.
41
42 @return Pointer to allocated memory.
43
44 @see my_aligned_free
45*/
46void *my_aligned_malloc(size_t size, size_t alignment);
47
48/**
49 Free allocated memory using my_aligned_malloc function.
50
51 @param[in] ptr Pointer to allocated memory using my_aligned_malloc function.
52*/
53void my_aligned_free(void *ptr);
54
55#endif /* __MY_ALIGNED_MALLOC_H__ */
void * my_aligned_malloc(size_t size, size_t alignment)
Function allocates size bytes and returns a pointer to the allocated memory.
Definition: my_aligned_malloc.cc:37
void my_aligned_free(void *ptr)
Free allocated memory using my_aligned_malloc function.
Definition: my_aligned_malloc.cc:62