-
Notifications
You must be signed in to change notification settings - Fork 0
/
clipboard.txt
173 lines (135 loc) · 4.96 KB
/
clipboard.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# view assembler
~/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-objdump -S build/esp32dev.ino.elf
# stack trace. copy 'back trace' addresses as argument
~/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/esp-2021r2-patch5-8.4.0/bin/xtensa-esp32-elf-addr2line -pfiaC -e build/esp32dev.ino.elf 0x400d1b14:0x3ffb21e0 0x400d1ce3:0x3ffb2200 0x400d26b5:0x3ffb2220 0x400d8c39:0x3ffb2290
git config --global credential.helper cache
git config --global credential.helper 'cache --timeout=36000'
git reset --hard HEAD
git add . && git commit -m "." && git push
TAG=$(date "+%Y-%m-%d--%H-%M") && git tag $TAG && git push origin $TAG
#pragma once
//
// implements a O(1) store of objects
//
// * Type is object type. 'Type' must contain public field '<IxType> alloc_ix'
// * Size is number of pre-allocated objects
// * IxType is type used to index in lists and should be unsigned with a bit
// width that fits 'Size'
// * StoreId is for debugging
// * InstanceSizeInBytes is custom size of instance
// used to fit largest object in an object hierarchy in lack of std::variant
//
// example:
// Type = sprite, Size = 255, IxType = uint8_t gives 255 allocatable sprites
// note. size should be at most the number that fits in IxType
// in example uint8_t fits 255 indexes
//
// note. no destructor since life-time is program life-time
//
template <typename Type, const unsigned Size, typename IxType,
const unsigned StoreId = 0, const unsigned InstanceSizeInBytes = 0>
class o1store {
Type *all_ = nullptr;
IxType *free_bgn_ = nullptr;
IxType *free_ptr_ = nullptr;
IxType *free_end_ = nullptr;
IxType *alloc_bgn_ = nullptr;
IxType *alloc_ptr_ = nullptr;
IxType alloc_ix_ = 0;
IxType *del_bgn_ = nullptr;
IxType *del_ptr_ = nullptr;
IxType *del_end_ = nullptr;
public:
o1store() {
if constexpr (InstanceSizeInBytes) {
all_ = (Type *)calloc(Size, InstanceSizeInBytes);
} else {
all_ = (Type *)calloc(Size, sizeof(Type));
}
free_ptr_ = free_bgn_ = (IxType *)calloc(Size, sizeof(IxType));
free_end_ = free_bgn_ + Size;
alloc_ptr_ = alloc_bgn_ = (IxType *)calloc(Size, sizeof(IxType));
del_ptr_ = del_bgn_ = (IxType *)calloc(Size, sizeof(IxType));
del_end_ = del_bgn_ + Size;
if (!all_ or !free_bgn_ or !alloc_bgn_ or !del_bgn_) {
Serial.printf("!!! o1store %u: could not allocate arrays\n", StoreId);
while (true)
;
}
IxType i = 0;
for (IxType *it = free_bgn_; it < free_end_; i++, it++) {
*it = i;
}
}
// virtual ~o1store() {
// free(all_);
// free(free_);
// free(alloc_);
// free(del_);
// }
// returns true if allocatable instances available
inline auto can_allocate() -> bool { return free_ptr_ < free_end_; }
// allocates an instance
auto allocate_instance() -> Type * {
if (free_ptr_ >= free_end_) {
return nullptr;
}
IxType ix = *free_ptr_;
free_ptr_++;
*alloc_ptr_ = ix;
alloc_ptr_++;
Type *inst = instance(ix);
inst->alloc_ix = alloc_ix_;
alloc_ix_++;
return inst;
}
// adds instance to a list that is applied with 'apply_free()'
void free_instance(const Type *inst) {
if (del_ptr_ >= del_end_) {
Serial.printf("!!! o1store %u: free overrun [alloc_ix=%u]\n", StoreId,
inst->alloc_ix);
while (true)
;
}
*del_ptr_ = alloc_bgn_[inst->alloc_ix];
del_ptr_++;
}
// de-allocates the instances that have been freed
void apply_free() {
for (IxType *it = del_bgn_; it < del_ptr_; it++) {
Type *inst_deleted = instance(*it);
alloc_ptr_--;
IxType inst_ix_to_move = *alloc_ptr_;
Type *inst_to_move = instance(inst_ix_to_move);
inst_to_move->alloc_ix = inst_deleted->alloc_ix;
alloc_bgn_[inst_deleted->alloc_ix] = inst_ix_to_move;
free_ptr_--;
*free_ptr_ = *it;
}
alloc_ix_ -= (del_ptr_ - del_bgn_);
del_ptr_ = del_bgn_;
}
// returns pointer to list of allocated instances
inline auto allocated_list() -> IxType * { return alloc_bgn_; }
// returns size of list of allocated instances
inline auto allocated_list_len() -> IxType { return alloc_ix_; }
// returns the list with all pre-allocated instances
inline auto all_list() -> Type * { return all_; }
// returns the size of 'all' list
constexpr auto all_list_len() -> unsigned { return Size; }
// returns instance from 'all' list at index 'ix'
inline auto instance(IxType ix) -> Type * {
if constexpr (!InstanceSizeInBytes) {
return &all_[ix];
}
// note. if instance size is specified do pointer shenanigans
return (Type *)((void *)all_ + InstanceSizeInBytes * ix);
}
// returns the size in bytes of allocated heap memory
constexpr auto allocated_data_size_B() -> size_t {
if constexpr (InstanceSizeInBytes) {
return Size * InstanceSizeInBytes + 3 * Size * sizeof(IxType);
}
return Size * sizeof(Type) + 3 * Size * sizeof(IxType);
}
};