src/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
9 / 9
100.0%
Branches:
1 / 2
50.0%
Functions:
4 / 4
100.0%

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 240 explicit Allocator(unsigned id) : id(id)
14 {
15 240 }
16
17 352794 inline ptr_t alloc(uint32_t size, int flag = 0)
18 {
19 352794 auto ptr = je_mallocx(size, id | flag | MALLOCX_ALIGN(8));
20 352794 return ptr;
21 }
22
23 10502 inline void dealloc(ptr_t ptr) { free(ptr); }
24
25 10502 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 10502 times.
10502 if (!ptr) return;
34 10502 je_dallocx(ptr, MALLOCX_TCACHE_NONE);
35 }
36
37 private:
38 unsigned id;
39 };
40
41 } // end namespace r2
42