Skip to content

Instantly share code, notes, and snippets.

@EricWF
Created July 31, 2019 00:45
Show Gist options
  • Save EricWF/7296e79cc90a57e505ebff4bad603d0c to your computer and use it in GitHub Desktop.
Save EricWF/7296e79cc90a57e505ebff4bad603d0c to your computer and use it in GitHub Desktop.
32000 : __front_spare() == 384 : __back_spare() == 383 : __capacity() == 32767 : bytes allocated == 32840
31000 : __front_spare() == 884 : __back_spare() == 883 : __capacity() == 32767 : bytes allocated == 32840
30000 : __front_spare() == 1384 : __back_spare() == 1383 : __capacity() == 32767 : bytes allocated == 32840
29000 : __front_spare() == 1884 : __back_spare() == 1883 : __capacity() == 32767 : bytes allocated == 32840
28000 : __front_spare() == 2384 : __back_spare() == 2383 : __capacity() == 32767 : bytes allocated == 32840
27000 : __front_spare() == 2884 : __back_spare() == 2883 : __capacity() == 32767 : bytes allocated == 32840
26000 : __front_spare() == 3384 : __back_spare() == 3383 : __capacity() == 32767 : bytes allocated == 32840
25000 : __front_spare() == 3884 : __back_spare() == 3883 : __capacity() == 32767 : bytes allocated == 32840
24000 : __front_spare() == 288 : __back_spare() == 287 : __capacity() == 24575 : bytes allocated == 24648
23000 : __front_spare() == 788 : __back_spare() == 787 : __capacity() == 24575 : bytes allocated == 24648
22000 : __front_spare() == 1288 : __back_spare() == 1287 : __capacity() == 24575 : bytes allocated == 24648
21000 : __front_spare() == 1788 : __back_spare() == 1787 : __capacity() == 24575 : bytes allocated == 24648
20000 : __front_spare() == 2288 : __back_spare() == 2287 : __capacity() == 24575 : bytes allocated == 24648
19000 : __front_spare() == 2788 : __back_spare() == 2787 : __capacity() == 24575 : bytes allocated == 24648
18000 : __front_spare() == 3288 : __back_spare() == 3287 : __capacity() == 24575 : bytes allocated == 24648
17000 : __front_spare() == 3788 : __back_spare() == 3787 : __capacity() == 24575 : bytes allocated == 24648
16000 : __front_spare() == 192 : __back_spare() == 191 : __capacity() == 16383 : bytes allocated == 16456
15000 : __front_spare() == 692 : __back_spare() == 691 : __capacity() == 16383 : bytes allocated == 16456
14000 : __front_spare() == 1192 : __back_spare() == 1191 : __capacity() == 16383 : bytes allocated == 16456
13000 : __front_spare() == 1692 : __back_spare() == 1691 : __capacity() == 16383 : bytes allocated == 16456
12000 : __front_spare() == 2192 : __back_spare() == 2191 : __capacity() == 16383 : bytes allocated == 16456
11000 : __front_spare() == 2692 : __back_spare() == 2691 : __capacity() == 16383 : bytes allocated == 16456
10000 : __front_spare() == 3192 : __back_spare() == 3191 : __capacity() == 16383 : bytes allocated == 16456
9000 : __front_spare() == 3692 : __back_spare() == 3691 : __capacity() == 16383 : bytes allocated == 16456
8000 : __front_spare() == 96 : __back_spare() == 95 : __capacity() == 8191 : bytes allocated == 8264
7000 : __front_spare() == 596 : __back_spare() == 595 : __capacity() == 8191 : bytes allocated == 8264
6000 : __front_spare() == 1096 : __back_spare() == 1095 : __capacity() == 8191 : bytes allocated == 8264
5000 : __front_spare() == 1596 : __back_spare() == 1595 : __capacity() == 8191 : bytes allocated == 8264
4000 : __front_spare() == 2096 : __back_spare() == 2095 : __capacity() == 8191 : bytes allocated == 8264
3000 : __front_spare() == 2596 : __back_spare() == 2595 : __capacity() == 8191 : bytes allocated == 8264
2000 : __front_spare() == 3096 : __back_spare() == 3095 : __capacity() == 8191 : bytes allocated == 8264
1000 : __front_spare() == 3596 : __back_spare() == 3595 : __capacity() == 8191 : bytes allocated == 8264
49 : __front_spare() == 4072 : __back_spare() == 4070 : __capacity() == 8191 : bytes allocated == 8264
48 : __front_spare() == 4072 : __back_spare() == 4071 : __capacity() == 8191 : bytes allocated == 8264
47 : __front_spare() == 4073 : __back_spare() == 4071 : __capacity() == 8191 : bytes allocated == 8264
46 : __front_spare() == 4073 : __back_spare() == 4072 : __capacity() == 8191 : bytes allocated == 8264
45 : __front_spare() == 4074 : __back_spare() == 4072 : __capacity() == 8191 : bytes allocated == 8264
44 : __front_spare() == 4074 : __back_spare() == 4073 : __capacity() == 8191 : bytes allocated == 8264
43 : __front_spare() == 4075 : __back_spare() == 4073 : __capacity() == 8191 : bytes allocated == 8264
42 : __front_spare() == 4075 : __back_spare() == 4074 : __capacity() == 8191 : bytes allocated == 8264
41 : __front_spare() == 4076 : __back_spare() == 4074 : __capacity() == 8191 : bytes allocated == 8264
40 : __front_spare() == 4076 : __back_spare() == 4075 : __capacity() == 8191 : bytes allocated == 8264
39 : __front_spare() == 4077 : __back_spare() == 4075 : __capacity() == 8191 : bytes allocated == 8264
38 : __front_spare() == 4077 : __back_spare() == 4076 : __capacity() == 8191 : bytes allocated == 8264
37 : __front_spare() == 4078 : __back_spare() == 4076 : __capacity() == 8191 : bytes allocated == 8264
36 : __front_spare() == 4078 : __back_spare() == 4077 : __capacity() == 8191 : bytes allocated == 8264
35 : __front_spare() == 4079 : __back_spare() == 4077 : __capacity() == 8191 : bytes allocated == 8264
34 : __front_spare() == 4079 : __back_spare() == 4078 : __capacity() == 8191 : bytes allocated == 8264
33 : __front_spare() == 4080 : __back_spare() == 4078 : __capacity() == 8191 : bytes allocated == 8264
32 : __front_spare() == 4080 : __back_spare() == 4079 : __capacity() == 8191 : bytes allocated == 8264
31 : __front_spare() == 4081 : __back_spare() == 4079 : __capacity() == 8191 : bytes allocated == 8264
30 : __front_spare() == 4081 : __back_spare() == 4080 : __capacity() == 8191 : bytes allocated == 8264
29 : __front_spare() == 4082 : __back_spare() == 4080 : __capacity() == 8191 : bytes allocated == 8264
28 : __front_spare() == 4082 : __back_spare() == 4081 : __capacity() == 8191 : bytes allocated == 8264
27 : __front_spare() == 4083 : __back_spare() == 4081 : __capacity() == 8191 : bytes allocated == 8264
26 : __front_spare() == 4083 : __back_spare() == 4082 : __capacity() == 8191 : bytes allocated == 8264
25 : __front_spare() == 4084 : __back_spare() == 4082 : __capacity() == 8191 : bytes allocated == 8264
24 : __front_spare() == 4084 : __back_spare() == 4083 : __capacity() == 8191 : bytes allocated == 8264
23 : __front_spare() == 4085 : __back_spare() == 4083 : __capacity() == 8191 : bytes allocated == 8264
22 : __front_spare() == 4085 : __back_spare() == 4084 : __capacity() == 8191 : bytes allocated == 8264
21 : __front_spare() == 4086 : __back_spare() == 4084 : __capacity() == 8191 : bytes allocated == 8264
20 : __front_spare() == 4086 : __back_spare() == 4085 : __capacity() == 8191 : bytes allocated == 8264
19 : __front_spare() == 4087 : __back_spare() == 4085 : __capacity() == 8191 : bytes allocated == 8264
18 : __front_spare() == 4087 : __back_spare() == 4086 : __capacity() == 8191 : bytes allocated == 8264
17 : __front_spare() == 4088 : __back_spare() == 4086 : __capacity() == 8191 : bytes allocated == 8264
16 : __front_spare() == 4088 : __back_spare() == 4087 : __capacity() == 8191 : bytes allocated == 8264
15 : __front_spare() == 4089 : __back_spare() == 4087 : __capacity() == 8191 : bytes allocated == 8264
14 : __front_spare() == 4089 : __back_spare() == 4088 : __capacity() == 8191 : bytes allocated == 8264
13 : __front_spare() == 4090 : __back_spare() == 4088 : __capacity() == 8191 : bytes allocated == 8264
12 : __front_spare() == 4090 : __back_spare() == 4089 : __capacity() == 8191 : bytes allocated == 8264
11 : __front_spare() == 4091 : __back_spare() == 4089 : __capacity() == 8191 : bytes allocated == 8264
10 : __front_spare() == 4091 : __back_spare() == 4090 : __capacity() == 8191 : bytes allocated == 8264
9 : __front_spare() == 4092 : __back_spare() == 4090 : __capacity() == 8191 : bytes allocated == 8264
8 : __front_spare() == 4092 : __back_spare() == 4091 : __capacity() == 8191 : bytes allocated == 8264
7 : __front_spare() == 4093 : __back_spare() == 4091 : __capacity() == 8191 : bytes allocated == 8264
6 : __front_spare() == 4093 : __back_spare() == 4092 : __capacity() == 8191 : bytes allocated == 8264
5 : __front_spare() == 4094 : __back_spare() == 4092 : __capacity() == 8191 : bytes allocated == 8264
4 : __front_spare() == 4094 : __back_spare() == 4093 : __capacity() == 8191 : bytes allocated == 8264
3 : __front_spare() == 4095 : __back_spare() == 4093 : __capacity() == 8191 : bytes allocated == 8264
2 : __front_spare() == 4095 : __back_spare() == 4094 : __capacity() == 8191 : bytes allocated == 8264
1 : __front_spare() == 4096 : __back_spare() == 4094 : __capacity() == 8191 : bytes allocated == 8264
0 : __front_spare() == 4096 : __back_spare() == 4095 : __capacity() == 8191 : bytes allocated == 8264
32000 : __front_spare() == 384 : __back_spare() == 4479 : __capacity() == 36863 : bytes allocated == 36936
31000 : __front_spare() == 884 : __back_spare() == 4979 : __capacity() == 36863 : bytes allocated == 36936
30000 : __front_spare() == 1384 : __back_spare() == 5479 : __capacity() == 36863 : bytes allocated == 36936
29000 : __front_spare() == 1884 : __back_spare() == 5979 : __capacity() == 36863 : bytes allocated == 36936
28000 : __front_spare() == 2384 : __back_spare() == 6479 : __capacity() == 36863 : bytes allocated == 36936
27000 : __front_spare() == 2884 : __back_spare() == 6979 : __capacity() == 36863 : bytes allocated == 36936
26000 : __front_spare() == 3384 : __back_spare() == 7479 : __capacity() == 36863 : bytes allocated == 36936
25000 : __front_spare() == 3884 : __back_spare() == 7979 : __capacity() == 36863 : bytes allocated == 36936
24000 : __front_spare() == 4384 : __back_spare() == 4383 : __capacity() == 32767 : bytes allocated == 32840
23000 : __front_spare() == 4884 : __back_spare() == 4883 : __capacity() == 32767 : bytes allocated == 32840
22000 : __front_spare() == 5384 : __back_spare() == 5383 : __capacity() == 32767 : bytes allocated == 32840
21000 : __front_spare() == 5884 : __back_spare() == 5883 : __capacity() == 32767 : bytes allocated == 32840
20000 : __front_spare() == 6384 : __back_spare() == 6383 : __capacity() == 32767 : bytes allocated == 32840
19000 : __front_spare() == 6884 : __back_spare() == 6883 : __capacity() == 32767 : bytes allocated == 32840
18000 : __front_spare() == 7384 : __back_spare() == 7383 : __capacity() == 32767 : bytes allocated == 32840
17000 : __front_spare() == 7884 : __back_spare() == 7883 : __capacity() == 32767 : bytes allocated == 32840
16000 : __front_spare() == 4288 : __back_spare() == 4287 : __capacity() == 24575 : bytes allocated == 24648
15000 : __front_spare() == 4788 : __back_spare() == 4787 : __capacity() == 24575 : bytes allocated == 24648
14000 : __front_spare() == 5288 : __back_spare() == 5287 : __capacity() == 24575 : bytes allocated == 24648
13000 : __front_spare() == 5788 : __back_spare() == 5787 : __capacity() == 24575 : bytes allocated == 24648
12000 : __front_spare() == 6288 : __back_spare() == 6287 : __capacity() == 24575 : bytes allocated == 24648
11000 : __front_spare() == 6788 : __back_spare() == 6787 : __capacity() == 24575 : bytes allocated == 24648
10000 : __front_spare() == 7288 : __back_spare() == 7287 : __capacity() == 24575 : bytes allocated == 24648
9000 : __front_spare() == 7788 : __back_spare() == 7787 : __capacity() == 24575 : bytes allocated == 24648
8000 : __front_spare() == 4192 : __back_spare() == 4191 : __capacity() == 16383 : bytes allocated == 16456
7000 : __front_spare() == 4692 : __back_spare() == 4691 : __capacity() == 16383 : bytes allocated == 16456
6000 : __front_spare() == 5192 : __back_spare() == 5191 : __capacity() == 16383 : bytes allocated == 16456
5000 : __front_spare() == 5692 : __back_spare() == 5691 : __capacity() == 16383 : bytes allocated == 16456
4000 : __front_spare() == 6192 : __back_spare() == 6191 : __capacity() == 16383 : bytes allocated == 16456
3000 : __front_spare() == 6692 : __back_spare() == 6691 : __capacity() == 16383 : bytes allocated == 16456
2000 : __front_spare() == 7192 : __back_spare() == 7191 : __capacity() == 16383 : bytes allocated == 16456
1000 : __front_spare() == 7692 : __back_spare() == 7691 : __capacity() == 16383 : bytes allocated == 16456
49 : __front_spare() == 8168 : __back_spare() == 8166 : __capacity() == 16383 : bytes allocated == 16456
48 : __front_spare() == 8168 : __back_spare() == 8167 : __capacity() == 16383 : bytes allocated == 16456
47 : __front_spare() == 8169 : __back_spare() == 8167 : __capacity() == 16383 : bytes allocated == 16456
46 : __front_spare() == 8169 : __back_spare() == 8168 : __capacity() == 16383 : bytes allocated == 16456
45 : __front_spare() == 8170 : __back_spare() == 8168 : __capacity() == 16383 : bytes allocated == 16456
44 : __front_spare() == 8170 : __back_spare() == 8169 : __capacity() == 16383 : bytes allocated == 16456
43 : __front_spare() == 8171 : __back_spare() == 8169 : __capacity() == 16383 : bytes allocated == 16456
42 : __front_spare() == 8171 : __back_spare() == 8170 : __capacity() == 16383 : bytes allocated == 16456
41 : __front_spare() == 8172 : __back_spare() == 8170 : __capacity() == 16383 : bytes allocated == 16456
40 : __front_spare() == 8172 : __back_spare() == 8171 : __capacity() == 16383 : bytes allocated == 16456
39 : __front_spare() == 8173 : __back_spare() == 8171 : __capacity() == 16383 : bytes allocated == 16456
38 : __front_spare() == 8173 : __back_spare() == 8172 : __capacity() == 16383 : bytes allocated == 16456
37 : __front_spare() == 8174 : __back_spare() == 8172 : __capacity() == 16383 : bytes allocated == 16456
36 : __front_spare() == 8174 : __back_spare() == 8173 : __capacity() == 16383 : bytes allocated == 16456
35 : __front_spare() == 8175 : __back_spare() == 8173 : __capacity() == 16383 : bytes allocated == 16456
34 : __front_spare() == 8175 : __back_spare() == 8174 : __capacity() == 16383 : bytes allocated == 16456
33 : __front_spare() == 8176 : __back_spare() == 8174 : __capacity() == 16383 : bytes allocated == 16456
32 : __front_spare() == 8176 : __back_spare() == 8175 : __capacity() == 16383 : bytes allocated == 16456
31 : __front_spare() == 8177 : __back_spare() == 8175 : __capacity() == 16383 : bytes allocated == 16456
30 : __front_spare() == 8177 : __back_spare() == 8176 : __capacity() == 16383 : bytes allocated == 16456
29 : __front_spare() == 8178 : __back_spare() == 8176 : __capacity() == 16383 : bytes allocated == 16456
28 : __front_spare() == 8178 : __back_spare() == 8177 : __capacity() == 16383 : bytes allocated == 16456
27 : __front_spare() == 8179 : __back_spare() == 8177 : __capacity() == 16383 : bytes allocated == 16456
26 : __front_spare() == 8179 : __back_spare() == 8178 : __capacity() == 16383 : bytes allocated == 16456
25 : __front_spare() == 8180 : __back_spare() == 8178 : __capacity() == 16383 : bytes allocated == 16456
24 : __front_spare() == 8180 : __back_spare() == 8179 : __capacity() == 16383 : bytes allocated == 16456
23 : __front_spare() == 8181 : __back_spare() == 8179 : __capacity() == 16383 : bytes allocated == 16456
22 : __front_spare() == 8181 : __back_spare() == 8180 : __capacity() == 16383 : bytes allocated == 16456
21 : __front_spare() == 8182 : __back_spare() == 8180 : __capacity() == 16383 : bytes allocated == 16456
20 : __front_spare() == 8182 : __back_spare() == 8181 : __capacity() == 16383 : bytes allocated == 16456
19 : __front_spare() == 8183 : __back_spare() == 8181 : __capacity() == 16383 : bytes allocated == 16456
18 : __front_spare() == 8183 : __back_spare() == 8182 : __capacity() == 16383 : bytes allocated == 16456
17 : __front_spare() == 8184 : __back_spare() == 8182 : __capacity() == 16383 : bytes allocated == 16456
16 : __front_spare() == 8184 : __back_spare() == 8183 : __capacity() == 16383 : bytes allocated == 16456
15 : __front_spare() == 8185 : __back_spare() == 8183 : __capacity() == 16383 : bytes allocated == 16456
14 : __front_spare() == 8185 : __back_spare() == 8184 : __capacity() == 16383 : bytes allocated == 16456
13 : __front_spare() == 8186 : __back_spare() == 8184 : __capacity() == 16383 : bytes allocated == 16456
12 : __front_spare() == 8186 : __back_spare() == 8185 : __capacity() == 16383 : bytes allocated == 16456
11 : __front_spare() == 8187 : __back_spare() == 8185 : __capacity() == 16383 : bytes allocated == 16456
10 : __front_spare() == 8187 : __back_spare() == 8186 : __capacity() == 16383 : bytes allocated == 16456
9 : __front_spare() == 8188 : __back_spare() == 8186 : __capacity() == 16383 : bytes allocated == 16456
8 : __front_spare() == 8188 : __back_spare() == 8187 : __capacity() == 16383 : bytes allocated == 16456
7 : __front_spare() == 8189 : __back_spare() == 8187 : __capacity() == 16383 : bytes allocated == 16456
6 : __front_spare() == 8189 : __back_spare() == 8188 : __capacity() == 16383 : bytes allocated == 16456
5 : __front_spare() == 8190 : __back_spare() == 8188 : __capacity() == 16383 : bytes allocated == 16456
4 : __front_spare() == 8190 : __back_spare() == 8189 : __capacity() == 16383 : bytes allocated == 16456
3 : __front_spare() == 8191 : __back_spare() == 8189 : __capacity() == 16383 : bytes allocated == 16456
2 : __front_spare() == 8191 : __back_spare() == 8190 : __capacity() == 16383 : bytes allocated == 16456
1 : __front_spare() == 4096 : __back_spare() == 8190 : __capacity() == 12287 : bytes allocated == 12360
0 : __front_spare() == 4096 : __back_spare() == 8191 : __capacity() == 12287 : bytes allocated == 12360
#include <deque>
#include <iostream>
#include <cassert>
#include "min_allocator.h"
#define DECL_FRIEND(N) template <class ...Args> auto std::__libcpp_test_friend<N>
using Friend = std::__libcpp_test_friend<0>;
template <>
struct std::__libcpp_test_friend<0> {
template <class Deque>
static void print(const Deque& d) {
std::cout << d.size()
<< " : __front_spare() == " << d.__front_spare()
<< " : __back_spare() == " << d.__back_spare()
<< " : __capacity() == " << d.__capacity()
<< " : bytes allocated == " << malloc_allocator_base::bytes_allocated << '\n';
}
static void test_basic();
};
void Friend::test_basic() {
std::deque<char, malloc_allocator<char> > d(32*1024, 'a');
bool take_from_front = true;
while (d.size() > 0)
{
if (take_from_front)
{
d.pop_front();
take_from_front = false;
}
else
{
d.pop_back();
take_from_front = true;
}
if (d.size() % 1000 == 0 || d.size() < 50)
{
print(d);
}
}
}
int main() {
Friend::test_basic();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment