memory/allocators/r2/allocator.hh
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include "jemalloc/jemalloc.h" | ||
| 4 | |||
| 5 | |||
| 6 | namespace r2 { | ||
| 7 | |||
| 8 | using ptr_t = void *; | ||
| 9 | |||
| 10 | class Allocator | ||
| 11 | { | ||
| 12 | public: | ||
| 13 | 234 | explicit Allocator(unsigned id) : id(id) | |
| 14 | { | ||
| 15 | 234 | } | |
| 16 | |||
| 17 | 352738 | inline ptr_t alloc(uint32_t size, int flag = 0) | |
| 18 | { | ||
| 19 | 352738 | auto ptr = je_mallocx(size, id | flag | MALLOCX_ALIGN(8)); | |
| 20 | 352738 | return ptr; | |
| 21 | } | ||
| 22 | |||
| 23 | 10462 | inline void dealloc(ptr_t ptr) { free(ptr); } | |
| 24 | |||
| 25 | 10462 | inline void free(ptr_t ptr) | |
| 26 | { | ||
| 27 | /*! | ||
| 28 | According to WenHao, using 0 is fine, because jemalloc will | ||
| 29 | automatically free the memory to this thread's allocation. | ||
| 30 | But according to my test, if using id has better scalability.d | ||
| 31 | */ | ||
| 32 | //jedallocx(ptr,0); | ||
| 33 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10462 times.
|
10462 | if (!ptr) return; |
| 34 | 10462 | je_dallocx(ptr, MALLOCX_TCACHE_NONE); | |
| 35 | } | ||
| 36 | |||
| 37 | private: | ||
| 38 | unsigned id; | ||
| 39 | }; | ||
| 40 | |||
| 41 | } // end namespace r2 | ||
| 42 |