LLVM 19.0.0git
rpnew.h
Go to the documentation of this file.
1//===-------------------------- rpnew.h -----------------*- C -*-=============//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This library provides a cross-platform lock free thread caching malloc
10// implementation in C11.
11//
12//===----------------------------------------------------------------------===//
13
14#ifdef __cplusplus
15
16#include <new>
17#include <rpmalloc.h>
18
19#ifndef __CRTDECL
20#define __CRTDECL
21#endif
22
23extern void __CRTDECL operator delete(void *p) noexcept { rpfree(p); }
24
25extern void __CRTDECL operator delete[](void *p) noexcept { rpfree(p); }
26
27extern void *__CRTDECL operator new(std::size_t size) noexcept(false) {
28 return rpmalloc(size);
29}
30
31extern void *__CRTDECL operator new[](std::size_t size) noexcept(false) {
32 return rpmalloc(size);
33}
34
35extern void *__CRTDECL operator new(std::size_t size,
36 const std::nothrow_t &tag) noexcept {
37 (void)sizeof(tag);
38 return rpmalloc(size);
39}
40
41extern void *__CRTDECL operator new[](std::size_t size,
42 const std::nothrow_t &tag) noexcept {
43 (void)sizeof(tag);
44 return rpmalloc(size);
45}
46
47#if (__cplusplus >= 201402L || _MSC_VER >= 1916)
48
49extern void __CRTDECL operator delete(void *p, std::size_t size) noexcept {
50 (void)sizeof(size);
51 rpfree(p);
52}
53
54extern void __CRTDECL operator delete[](void *p, std::size_t size) noexcept {
55 (void)sizeof(size);
56 rpfree(p);
57}
58
59#endif
60
61#if (__cplusplus > 201402L || defined(__cpp_aligned_new))
62
63extern void __CRTDECL operator delete(void *p,
64 std::align_val_t align) noexcept {
65 (void)sizeof(align);
66 rpfree(p);
67}
68
69extern void __CRTDECL operator delete[](void *p,
70 std::align_val_t align) noexcept {
71 (void)sizeof(align);
72 rpfree(p);
73}
74
75extern void __CRTDECL operator delete(void *p, std::size_t size,
76 std::align_val_t align) noexcept {
77 (void)sizeof(size);
78 (void)sizeof(align);
79 rpfree(p);
80}
81
82extern void __CRTDECL operator delete[](void *p, std::size_t size,
83 std::align_val_t align) noexcept {
84 (void)sizeof(size);
85 (void)sizeof(align);
86 rpfree(p);
87}
88
89extern void *__CRTDECL operator new(std::size_t size,
90 std::align_val_t align) noexcept(false) {
91 return rpaligned_alloc(static_cast<size_t>(align), size);
92}
93
94extern void *__CRTDECL operator new[](std::size_t size,
95 std::align_val_t align) noexcept(false) {
96 return rpaligned_alloc(static_cast<size_t>(align), size);
97}
98
99extern void *__CRTDECL operator new(std::size_t size, std::align_val_t align,
100 const std::nothrow_t &tag) noexcept {
101 (void)sizeof(tag);
102 return rpaligned_alloc(static_cast<size_t>(align), size);
103}
104
105extern void *__CRTDECL operator new[](std::size_t size, std::align_val_t align,
106 const std::nothrow_t &tag) noexcept {
107 (void)sizeof(tag);
108 return rpaligned_alloc(static_cast<size_t>(align), size);
109}
110
111#endif
112
113#endif
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1680
void rpfree(void *ptr)
Free the given memory block.
Definition: rpmalloc.c:3385
RPMALLOC_ALLOCATOR void * rpmalloc(size_t size)
Allocate a memory block of at least the given size.
Definition: rpmalloc.c:3374
RPMALLOC_ALLOCATOR void * rpaligned_alloc(size_t alignment, size_t size)
Allocate a memory block of at least the given size and alignment.
Definition: rpmalloc.c:3438