cpp

Coverage Report

Created: 2023-03-07 20:24

/home/andy/git/oilshell/oil/mycpp/bump_leak_heap.h
Line
Count
Source
1
// mycpp/bump_leak_heap.h: Leaky Bump Allocator
2
3
#ifndef MYCPP_BUMP_LEAK_HEAP_H
4
#define MYCPP_BUMP_LEAK_HEAP_H
5
6
#include <stdint.h>  // int64_t
7
8
#include "mycpp/common.h"
9
#include "mycpp/gc_obj.h"
10
11
class BumpLeakHeap {
12
 public:
13
  // reserve 32 frames to start
14
3
  BumpLeakHeap() {
15
3
  }
16
17
2
  void Init() {
18
2
  }
19
1
  void Init(int gc_threshold) {
20
1
  }
21
22
1
  void PushRoot(RawObject** p) {
23
1
  }
24
1
  void PopRoot() {
25
1
  }
26
1
  void RootGlobalVar(void* root) {
27
1
  }
28
29
  void* Allocate(size_t num_bytes);
30
  void* Reallocate(void* p, size_t num_bytes);
31
1
  int MaybeCollect() {
32
1
    return -1;  // no collection attempted
33
1
  }
34
35
  void PrintStats(int fd);
36
37
  void CleanProcessExit();
38
  void FastProcessExit();
39
40
  bool is_initialized_ = true;  // mark/sweep doesn't need to be initialized
41
42
  // In number of live objects, since we aren't keeping track of total bytes
43
  int gc_threshold_;
44
  int mem_pos_ = 0;
45
46
  // Cumulative stats
47
  int num_allocated_ = 0;
48
  int64_t bytes_allocated_ = 0;  // avoid overflow
49
};
50
51
#if defined(BUMP_LEAK)
52
extern BumpLeakHeap gHeap;
53
#endif
54
55
#endif  // MYCPP_BUMP_LEAK_HEAP_H