blob: 5116b29f212f55ca25292baebb85cd0fa43b44c4 [file] [log] [blame]
Brian Silverman20350ac2021-11-17 18:19:55 -08001// -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*-
Austin Schuh745610d2015-09-06 18:19:50 -07002/* Copyright (c) 2003, Google Inc.
3 * All rights reserved.
Brian Silverman20350ac2021-11-17 18:19:55 -08004 *
Austin Schuh745610d2015-09-06 18:19:50 -07005 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
Brian Silverman20350ac2021-11-17 18:19:55 -08008 *
Austin Schuh745610d2015-09-06 18:19:50 -07009 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
Brian Silverman20350ac2021-11-17 18:19:55 -080018 *
Austin Schuh745610d2015-09-06 18:19:50 -070019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * ---
32 * Author: Sanjay Ghemawat <opensource@google.com>
Brian Silverman20350ac2021-11-17 18:19:55 -080033 * .h file by Craig Silverstein <opensource@google.com>
Austin Schuh745610d2015-09-06 18:19:50 -070034 */
35
36#ifndef TCMALLOC_TCMALLOC_H_
37#define TCMALLOC_TCMALLOC_H_
38
Brian Silverman20350ac2021-11-17 18:19:55 -080039#include <stddef.h> /* for size_t */
40#ifdef __cplusplus
41#include <new> /* for std::nothrow_t, std::align_val_t */
Austin Schuh745610d2015-09-06 18:19:50 -070042#endif
43
Brian Silverman20350ac2021-11-17 18:19:55 -080044/* Define the version number so folks can check against it */
Austin Schuh745610d2015-09-06 18:19:50 -070045#define TC_VERSION_MAJOR 2
Brian Silverman20350ac2021-11-17 18:19:55 -080046#define TC_VERSION_MINOR 9
47#define TC_VERSION_PATCH ".1"
48#define TC_VERSION_STRING "gperftools 2.9.1"
Austin Schuh745610d2015-09-06 18:19:50 -070049
Brian Silverman20350ac2021-11-17 18:19:55 -080050#ifndef PERFTOOLS_NOTHROW
Austin Schuh745610d2015-09-06 18:19:50 -070051
Brian Silverman20350ac2021-11-17 18:19:55 -080052#if __cplusplus >= 201103L
53#define PERFTOOLS_NOTHROW noexcept
54#elif defined(__cplusplus)
55#define PERFTOOLS_NOTHROW throw()
56#else
57# ifdef __GNUC__
58# define PERFTOOLS_NOTHROW __attribute__((__nothrow__))
59# else
60# define PERFTOOLS_NOTHROW
61# endif
62#endif
63
64#endif
65
Austin Schuh745610d2015-09-06 18:19:50 -070066#ifndef PERFTOOLS_DLL_DECL
67# ifdef _WIN32
68# define PERFTOOLS_DLL_DECL __declspec(dllimport)
69# else
70# define PERFTOOLS_DLL_DECL
71# endif
72#endif
73
74#ifdef __cplusplus
Austin Schuh745610d2015-09-06 18:19:50 -070075extern "C" {
76#endif
Brian Silverman20350ac2021-11-17 18:19:55 -080077 /*
78 * Returns a human-readable version string. If major, minor,
79 * and/or patch are not NULL, they are set to the major version,
80 * minor version, and patch-code (a string, usually "").
81 */
Austin Schuh745610d2015-09-06 18:19:50 -070082 PERFTOOLS_DLL_DECL const char* tc_version(int* major, int* minor,
Brian Silverman20350ac2021-11-17 18:19:55 -080083 const char** patch) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -070084
Brian Silverman20350ac2021-11-17 18:19:55 -080085 PERFTOOLS_DLL_DECL void* tc_malloc(size_t size) PERFTOOLS_NOTHROW;
86 PERFTOOLS_DLL_DECL void* tc_malloc_skip_new_handler(size_t size) PERFTOOLS_NOTHROW;
87 PERFTOOLS_DLL_DECL void tc_free(void* ptr) PERFTOOLS_NOTHROW;
88 PERFTOOLS_DLL_DECL void tc_free_sized(void *ptr, size_t size) PERFTOOLS_NOTHROW;
89 PERFTOOLS_DLL_DECL void* tc_realloc(void* ptr, size_t size) PERFTOOLS_NOTHROW;
90 PERFTOOLS_DLL_DECL void* tc_calloc(size_t nmemb, size_t size) PERFTOOLS_NOTHROW;
91 PERFTOOLS_DLL_DECL void tc_cfree(void* ptr) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -070092
93 PERFTOOLS_DLL_DECL void* tc_memalign(size_t __alignment,
Brian Silverman20350ac2021-11-17 18:19:55 -080094 size_t __size) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -070095 PERFTOOLS_DLL_DECL int tc_posix_memalign(void** ptr,
Brian Silverman20350ac2021-11-17 18:19:55 -080096 size_t align, size_t size) PERFTOOLS_NOTHROW;
97 PERFTOOLS_DLL_DECL void* tc_valloc(size_t __size) PERFTOOLS_NOTHROW;
98 PERFTOOLS_DLL_DECL void* tc_pvalloc(size_t __size) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -070099
Brian Silverman20350ac2021-11-17 18:19:55 -0800100 PERFTOOLS_DLL_DECL void tc_malloc_stats(void) PERFTOOLS_NOTHROW;
101 PERFTOOLS_DLL_DECL int tc_mallopt(int cmd, int value) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -0700102
Brian Silverman20350ac2021-11-17 18:19:55 -0800103 /*
104 * This is an alias for MallocExtension::instance()->GetAllocatedSize().
105 * It is equivalent to
106 * OS X: malloc_size()
107 * glibc: malloc_usable_size()
108 * Windows: _msize()
109 */
110 PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -0700111
112#ifdef __cplusplus
Brian Silverman20350ac2021-11-17 18:19:55 -0800113 PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -0700114 PERFTOOLS_DLL_DECL void* tc_new(size_t size);
115 PERFTOOLS_DLL_DECL void* tc_new_nothrow(size_t size,
Brian Silverman20350ac2021-11-17 18:19:55 -0800116 const std::nothrow_t&) PERFTOOLS_NOTHROW;
117 PERFTOOLS_DLL_DECL void tc_delete(void* p) PERFTOOLS_NOTHROW;
118 PERFTOOLS_DLL_DECL void tc_delete_sized(void* p, size_t size) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -0700119 PERFTOOLS_DLL_DECL void tc_delete_nothrow(void* p,
Brian Silverman20350ac2021-11-17 18:19:55 -0800120 const std::nothrow_t&) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -0700121 PERFTOOLS_DLL_DECL void* tc_newarray(size_t size);
122 PERFTOOLS_DLL_DECL void* tc_newarray_nothrow(size_t size,
Brian Silverman20350ac2021-11-17 18:19:55 -0800123 const std::nothrow_t&) PERFTOOLS_NOTHROW;
124 PERFTOOLS_DLL_DECL void tc_deletearray(void* p) PERFTOOLS_NOTHROW;
125 PERFTOOLS_DLL_DECL void tc_deletearray_sized(void* p, size_t size) PERFTOOLS_NOTHROW;
Austin Schuh745610d2015-09-06 18:19:50 -0700126 PERFTOOLS_DLL_DECL void tc_deletearray_nothrow(void* p,
Brian Silverman20350ac2021-11-17 18:19:55 -0800127 const std::nothrow_t&) PERFTOOLS_NOTHROW;
128
129#if defined(__cpp_aligned_new) || (defined(_MSVC_LANG) && _MSVC_LANG > 201402L)
130 PERFTOOLS_DLL_DECL void* tc_new_aligned(size_t size, std::align_val_t al);
131 PERFTOOLS_DLL_DECL void* tc_new_aligned_nothrow(size_t size, std::align_val_t al,
132 const std::nothrow_t&) PERFTOOLS_NOTHROW;
133 PERFTOOLS_DLL_DECL void tc_delete_aligned(void* p, std::align_val_t al) PERFTOOLS_NOTHROW;
134 PERFTOOLS_DLL_DECL void tc_delete_sized_aligned(void* p, size_t size, std::align_val_t al) PERFTOOLS_NOTHROW;
135 PERFTOOLS_DLL_DECL void tc_delete_aligned_nothrow(void* p, std::align_val_t al,
136 const std::nothrow_t&) PERFTOOLS_NOTHROW;
137 PERFTOOLS_DLL_DECL void* tc_newarray_aligned(size_t size, std::align_val_t al);
138 PERFTOOLS_DLL_DECL void* tc_newarray_aligned_nothrow(size_t size, std::align_val_t al,
139 const std::nothrow_t&) PERFTOOLS_NOTHROW;
140 PERFTOOLS_DLL_DECL void tc_deletearray_aligned(void* p, std::align_val_t al) PERFTOOLS_NOTHROW;
141 PERFTOOLS_DLL_DECL void tc_deletearray_sized_aligned(void* p, size_t size, std::align_val_t al) PERFTOOLS_NOTHROW;
142 PERFTOOLS_DLL_DECL void tc_deletearray_aligned_nothrow(void* p, std::align_val_t al,
143 const std::nothrow_t&) PERFTOOLS_NOTHROW;
144#endif
Austin Schuh745610d2015-09-06 18:19:50 -0700145}
146#endif
147
Brian Silverman20350ac2021-11-17 18:19:55 -0800148/* We're only un-defining for public */
149#if !defined(GPERFTOOLS_CONFIG_H_)
150
151#undef PERFTOOLS_NOTHROW
152
153#endif /* GPERFTOOLS_CONFIG_H_ */
154
155#endif /* #ifndef TCMALLOC_TCMALLOC_H_ */