VR-Vantage 3.0.3 API Documentation
Home
Modules
Namespaces
Classes
Files
Libraries
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
include
TracyClient
client
tracy_rpmalloc.hpp
Go to the documentation of this file.
1
/* rpmalloc.h - Memory allocator - Public Domain - 2016 Mattias Jansson
2
*
3
* This library provides a cross-platform lock free thread caching malloc implementation in C11.
4
* The latest source code is always available at
5
*
6
* https://github.com/mjansson/rpmalloc
7
*
8
* This library is put in the public domain; you can redistribute it and/or modify it without any restrictions.
9
*
10
*/
11
12
#pragma once
13
14
#include <stddef.h>
15
#include "../common/TracyApi.h"
16
17
namespace
tracy
18
{
19
20
#if defined(__clang__) || defined(__GNUC__)
21
# define RPMALLOC_EXPORT __attribute__((visibility("default")))
22
# define RPMALLOC_ALLOCATOR
23
# define RPMALLOC_ATTRIB_MALLOC __attribute__((__malloc__))
24
# if defined(__clang_major__) && (__clang_major__ < 4)
25
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
26
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size)
27
# else
28
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size) __attribute__((alloc_size(size)))
29
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count, size) __attribute__((alloc_size(count, size)))
30
# endif
31
# define RPMALLOC_CDECL
32
#elif defined(_MSC_VER)
33
# define RPMALLOC_EXPORT
34
# define RPMALLOC_ALLOCATOR __declspec(allocator) __declspec(restrict)
35
# define RPMALLOC_ATTRIB_MALLOC
36
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
37
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size)
38
# define RPMALLOC_CDECL __cdecl
39
#else
40
# define RPMALLOC_EXPORT
41
# define RPMALLOC_ALLOCATOR
42
# define RPMALLOC_ATTRIB_MALLOC
43
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
44
# define RPMALLOC_ATTRIB_ALLOC_SIZE2(count,size)
45
# define RPMALLOC_CDECL
46
#endif
47
49
#ifndef RPMALLOC_CONFIGURABLE
50
#define RPMALLOC_CONFIGURABLE 0
51
#endif
52
54
#define RPMALLOC_NO_PRESERVE 1
55
56
typedef
struct
rpmalloc_global_statistics_t
{
58
size_t
mapped
;
60
size_t
mapped_peak
;
62
size_t
cached
;
64
size_t
huge_alloc
;
66
size_t
huge_alloc_peak
;
68
size_t
mapped_total
;
70
size_t
unmapped_total
;
71
}
rpmalloc_global_statistics_t
;
72
73
typedef
struct
rpmalloc_thread_statistics_t
{
75
size_t
sizecache
;
77
size_t
spancache
;
79
size_t
thread_to_global
;
81
size_t
global_to_thread
;
83
struct
{
85
size_t
current
;
87
size_t
peak
;
89
size_t
to_global
;
91
size_t
from_global
;
93
size_t
to_cache
;
95
size_t
from_cache
;
97
size_t
to_reserved
;
99
size_t
from_reserved
;
101
size_t
map_calls
;
102
}
span_use
[32];
104
struct
{
106
size_t
alloc_current
;
108
size_t
alloc_peak
;
110
size_t
alloc_total
;
112
size_t
free_total
;
114
size_t
spans_to_cache
;
116
size_t
spans_from_cache
;
118
size_t
spans_from_reserved
;
120
size_t
map_calls
;
121
}
size_use
[128];
122
}
rpmalloc_thread_statistics_t
;
123
124
typedef
struct
rpmalloc_config_t
{
126
// aligned to the rpmalloc span size, which will always be a power of two.
127
// Optionally the function can store an alignment offset in the offset variable
128
// in case it performs alignment and the returned pointer is offset from the
129
// actual start of the memory region due to this alignment. The alignment offset
130
// will be passed to the memory unmap function. The alignment offset MUST NOT be
131
// larger than 65535 (storable in an uint16_t), if it is you must use natural
132
// alignment to shift it into 16 bits. If you set a memory_map function, you
133
// must also set a memory_unmap function or else the default implementation will
134
// be used for both.
135
void
* (*memory_map)(
size_t
size
,
size_t
*
offset
);
137
// If release is set to non-zero, the unmap is for an entire span range as returned by
138
// a previous call to memory_map and that the entire range should be released. The
139
// release argument holds the size of the entire span range. If release is set to 0,
140
// the unmap is a partial decommit of a subset of the mapped memory range.
141
// If you set a memory_unmap function, you must also set a memory_map function or
142
// else the default implementation will be used for both.
143
void
(*
memory_unmap
)(
void
*
address
,
size_t
size
,
size_t
offset
,
size_t
release);
145
// requests to memory_map will be made with size set to a multiple of the page size.
146
// Used if RPMALLOC_CONFIGURABLE is defined to 1, otherwise system page size is used.
147
size_t
page_size
;
149
// range (unless 0 - set to 0 to use the default span size). Used if RPMALLOC_CONFIGURABLE
150
// is defined to 1.
151
size_t
span_size
;
153
// be used to minimize the system call overhead at the cost of virtual memory address
154
// space. The extra mapped pages will not be written until actually used, so physical
155
// committed memory should not be affected in the default implementation. Will be
156
// aligned to a multiple of spans that match memory page size in case of huge pages.
157
size_t
span_map_count
;
159
// zero, the allocator will try to enable huge pages and auto detect the configuration.
160
// If this is set to non-zero and page_size is also non-zero, the allocator will
161
// assume huge pages have been configured and enabled prior to initializing the
162
// allocator.
163
// For Windows, see https://docs.microsoft.com/en-us/windows/desktop/memory/large-page-support
164
// For Linux, see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt
165
int
enable_huge_pages
;
166
}
rpmalloc_config_t
;
167
169
TRACY_API
int
170
rpmalloc_initialize
(
void
);
171
173
RPMALLOC_EXPORT
int
174
rpmalloc_initialize_config
(
const
rpmalloc_config_t
* config);
175
177
RPMALLOC_EXPORT
const
rpmalloc_config_t
*
178
rpmalloc_config
(
void
);
179
181
TRACY_API
void
182
rpmalloc_finalize
(
void
);
183
185
TRACY_API
void
186
rpmalloc_thread_initialize
(
void
);
187
189
TRACY_API
void
190
rpmalloc_thread_finalize
(
void
);
191
193
RPMALLOC_EXPORT
void
194
rpmalloc_thread_collect
(
void
);
195
197
RPMALLOC_EXPORT
int
198
rpmalloc_is_thread_initialized
(
void
);
199
201
RPMALLOC_EXPORT
void
202
rpmalloc_thread_statistics
(
rpmalloc_thread_statistics_t
* stats);
203
205
RPMALLOC_EXPORT
void
206
rpmalloc_global_statistics
(
rpmalloc_global_statistics_t
* stats);
207
209
RPMALLOC_EXPORT
void
210
rpmalloc_dump_statistics
(
void
* file);
211
213
TRACY_API
RPMALLOC_ALLOCATOR
void
*
214
rpmalloc
(
size_t
size
)
RPMALLOC_ATTRIB_MALLOC
RPMALLOC_ATTRIB_ALLOC_SIZE
(1);
215
217
TRACY_API
void
218
rpfree
(
void
* ptr);
219
221
RPMALLOC_EXPORT
RPMALLOC_ALLOCATOR
void
*
222
rpcalloc
(
size_t
num
,
size_t
size
)
RPMALLOC_ATTRIB_MALLOC
RPMALLOC_ATTRIB_ALLOC_SIZE2
(1, 2);
223
225
TRACY_API
RPMALLOC_ALLOCATOR
void
*
226
rprealloc
(
void
* ptr,
size_t
size
)
RPMALLOC_ATTRIB_MALLOC
RPMALLOC_ATTRIB_ALLOC_SIZE
(2);
227
229
// with optional control flags (see RPMALLOC_NO_PRESERVE).
230
// Alignment must be a power of two and a multiple of sizeof(void*),
231
// and should ideally be less than memory page size. A caveat of rpmalloc
232
// internals is that this must also be strictly less than the span size (default 64KiB)
233
RPMALLOC_EXPORT
RPMALLOC_ALLOCATOR
void
*
234
rpaligned_realloc
(
void
* ptr,
size_t
alignment,
size_t
size
,
size_t
oldsize,
unsigned
int
flags
)
RPMALLOC_ATTRIB_MALLOC
RPMALLOC_ATTRIB_ALLOC_SIZE
(3);
235
237
// Alignment must be a power of two and a multiple of sizeof(void*),
238
// and should ideally be less than memory page size. A caveat of rpmalloc
239
// internals is that this must also be strictly less than the span size (default 64KiB)
240
RPMALLOC_EXPORT
RPMALLOC_ALLOCATOR
void
*
241
rpaligned_alloc
(
size_t
alignment,
size_t
size
)
RPMALLOC_ATTRIB_MALLOC
RPMALLOC_ATTRIB_ALLOC_SIZE
(2);
242
244
// Alignment must be a power of two and a multiple of sizeof(void*),
245
// and should ideally be less than memory page size. A caveat of rpmalloc
246
// internals is that this must also be strictly less than the span size (default 64KiB)
247
RPMALLOC_EXPORT
RPMALLOC_ALLOCATOR
void
*
248
rpmemalign
(
size_t
alignment,
size_t
size
)
RPMALLOC_ATTRIB_MALLOC
RPMALLOC_ATTRIB_ALLOC_SIZE
(2);
249
251
// Alignment must be a power of two and a multiple of sizeof(void*),
252
// and should ideally be less than memory page size. A caveat of rpmalloc
253
// internals is that this must also be strictly less than the span size (default 64KiB)
254
RPMALLOC_EXPORT
int
255
rpposix_memalign
(
void
**memptr,
size_t
alignment,
size_t
size
);
256
258
RPMALLOC_EXPORT
size_t
259
rpmalloc_usable_size
(
void
* ptr);
260
261
}
Copyright © 2005-2023 MAK Technologies. All Rights Reserved (
www.mak.com
)