github.com/pidato/unsafe@v0.1.4/memory/rpmalloc/rpnew.h (about)

     1  
     2  #ifdef __cplusplus
     3  
     4  #include <new>
     5  #include <rpmalloc.h>
     6  
     7  #ifndef __CRTDECL
     8  #define __CRTDECL
     9  #endif
    10  
    11  extern void __CRTDECL
    12  operator delete(void* p) noexcept {
    13  	rpfree(p);
    14  }
    15  
    16  extern void __CRTDECL
    17  operator delete[](void* p) noexcept {
    18  	rpfree(p);
    19  }
    20  
    21  extern void* __CRTDECL
    22  operator new(std::size_t size) noexcept(false) {
    23  	return rpmalloc(size);
    24  }
    25  
    26  extern void* __CRTDECL
    27  operator new[](std::size_t size) noexcept(false) {
    28  	return rpmalloc(size);
    29  }
    30  
    31  extern void* __CRTDECL
    32  operator new(std::size_t size, const std::nothrow_t& tag) noexcept {
    33  	(void)sizeof(tag);
    34  	return rpmalloc(size);
    35  }
    36  
    37  extern void* __CRTDECL
    38  operator new[](std::size_t size, const std::nothrow_t& tag) noexcept {
    39  	(void)sizeof(tag);
    40  	return rpmalloc(size);
    41  }
    42  
    43  #if (__cplusplus >= 201402L || _MSC_VER >= 1916)
    44  
    45  extern void __CRTDECL
    46  operator delete(void* p, std::size_t size) noexcept {
    47  	(void)sizeof(size);
    48  	rpfree(p);
    49  }
    50  
    51  extern void __CRTDECL
    52  operator delete[](void* p, std::size_t size) noexcept {
    53  	(void)sizeof(size);
    54  	rpfree(p);
    55  }
    56  
    57  #endif
    58  
    59  #if (__cplusplus > 201402L || defined(__cpp_aligned_new))
    60  
    61  extern void __CRTDECL
    62  operator delete(void* p, std::align_val_t align) noexcept {
    63  	(void)sizeof(align);
    64  	rpfree(p);
    65  }
    66  
    67  extern void __CRTDECL
    68  operator delete[](void* p, std::align_val_t align) noexcept {
    69  	(void)sizeof(align);
    70  	rpfree(p);
    71  }
    72  
    73  extern void __CRTDECL
    74  operator delete(void* p, std::size_t size, std::align_val_t align) noexcept {
    75  	(void)sizeof(size);
    76  	(void)sizeof(align);
    77  	rpfree(p);
    78  }
    79  
    80  extern void __CRTDECL
    81  operator delete[](void* p, std::size_t size, std::align_val_t align) noexcept {
    82  	(void)sizeof(size);
    83  	(void)sizeof(align);
    84  	rpfree(p);
    85  }
    86  
    87  extern void* __CRTDECL
    88  operator new(std::size_t size, std::align_val_t align) noexcept(false) {
    89  	return rpaligned_alloc(static_cast<size_t>(align), size);
    90  }
    91  
    92  extern void* __CRTDECL
    93  operator new[](std::size_t size, std::align_val_t align) noexcept(false) {
    94  	return rpaligned_alloc(static_cast<size_t>(align), size);
    95  }
    96  
    97  extern void* __CRTDECL
    98  operator new(std::size_t size, std::align_val_t align, const std::nothrow_t& tag) noexcept {
    99  	(void)sizeof(tag);
   100  	return rpaligned_alloc(static_cast<size_t>(align), size);
   101  }
   102  
   103  extern void* __CRTDECL
   104  operator new[](std::size_t size, std::align_val_t align, const std::nothrow_t& tag) noexcept {
   105  	(void)sizeof(tag);
   106  	return rpaligned_alloc(static_cast<size_t>(align), size);
   107  }
   108  
   109  #endif
   110  
   111  #endif