| 1 | #ifndef __TRACYALLOC_HPP__ |
| 2 | #define __TRACYALLOC_HPP__ |
| 3 | |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | #if defined TRACY_ENABLE && !defined __EMSCRIPTEN__ |
| 7 | # include "TracyApi.h" |
| 8 | # include "TracyForceInline.hpp" |
| 9 | # include "../client/tracy_rpmalloc.hpp" |
| 10 | # define TRACY_USE_RPMALLOC |
| 11 | #endif |
| 12 | |
| 13 | namespace tracy |
| 14 | { |
| 15 | |
| 16 | #ifdef TRACY_USE_RPMALLOC |
| 17 | TRACY_API void InitRpmalloc(); |
| 18 | #else |
| 19 | static inline void InitRpmalloc() {} |
| 20 | #endif |
| 21 | |
| 22 | static inline void* tracy_malloc( size_t size ) |
| 23 | { |
| 24 | #ifdef TRACY_USE_RPMALLOC |
| 25 | InitRpmalloc(); |
| 26 | return rpmalloc( size ); |
| 27 | #else |
| 28 | return malloc( size ); |
| 29 | #endif |
| 30 | } |
| 31 | |
| 32 | static inline void* tracy_malloc_fast( size_t size ) |
| 33 | { |
| 34 | #ifdef TRACY_USE_RPMALLOC |
| 35 | return rpmalloc( size ); |
| 36 | #else |
| 37 | return malloc( size ); |
| 38 | #endif |
| 39 | } |
| 40 | |
| 41 | static inline void tracy_free( void* ptr ) |
| 42 | { |
| 43 | #ifdef TRACY_USE_RPMALLOC |
| 44 | InitRpmalloc(); |
| 45 | rpfree( ptr ); |
| 46 | #else |
| 47 | free( ptr ); |
| 48 | #endif |
| 49 | } |
| 50 | |
| 51 | static inline void tracy_free_fast( void* ptr ) |
| 52 | { |
| 53 | #ifdef TRACY_USE_RPMALLOC |
| 54 | rpfree( ptr ); |
| 55 | #else |
| 56 | free( ptr ); |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | static inline void* tracy_realloc( void* ptr, size_t size ) |
| 61 | { |
| 62 | #ifdef TRACY_USE_RPMALLOC |
| 63 | InitRpmalloc(); |
| 64 | return rprealloc( ptr, size ); |
| 65 | #else |
| 66 | return realloc( ptr, size ); |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | } |
| 71 | |
| 72 | #endif |