MySQL 8.0.40
Source Code Documentation
my_aligned_malloc.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 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 __MY_ALIGNED_MALLOC_H__
25#define __MY_ALIGNED_MALLOC_H__
26
27#include <cstddef>
28
29/**
30 Function allocates size bytes and returns a pointer to the allocated memory.
31 Size and alignment parameters depend on platform on which the function is
32 executed. Please check posix_memalign, memalign and _aligned_malloc functions
33 for details. To conform with all platforms size should be multiple of aligment
34 and aligment should be power of two.
35
36 We can use C++17 aligned new/aligned delete on non-windows platforms once the
37 minimum supported version of tcmalloc becomes >= 2.6.2. Right now TC malloc
38 crashes.
39
40 @param[in] size Multiple of alignment.
41 @param[in] alignment Memory aligment, which must be power of two.
42
43 @return Pointer to allocated memory.
44
45 @see my_aligned_free
46*/
47void *my_aligned_malloc(size_t size, size_t alignment);
48
49/**
50 Free allocated memory using my_aligned_malloc function.
51
52 @param[in] ptr Pointer to allocated memory using my_aligned_malloc function.
53*/
54void my_aligned_free(void *ptr);
55
56#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:38
void my_aligned_free(void *ptr)
Free allocated memory using my_aligned_malloc function.
Definition: my_aligned_malloc.cc:63