История изменений
Исправление quasimoto, (текущая версия) :
std::vector< std::vector< T> >
std::vector<std::vector<int>> xs = {{1, 2, 3}, {1, 2}, {1}, {}};
for (auto const& col : xs) {
for (auto const& el : col)
printf("(%p)%d ", &el, el);
puts("");
}
/*
(0x59f91d0)1 (0x59f91d4)2 (0x59f91d8)3
(0x59f9220)1 (0x59f9224)2
(0x59f9270)1
*/
/*
total heap usage: 7 allocs, 7 frees, 144 bytes allocated
*/
144/4 = 36, куда ему столько? :)
int xs[][3] = {{1, 2, 3}, {1, 2}, {1}, {}};
for (auto const& col : xs) {
for (auto const& el : col)
printf("(%p)%d ", &el, el);
puts("");
}
/*
(0x7ff0000e0)1 (0x7ff0000e4)2 (0x7ff0000e8)3
(0x7ff0000ec)1 (0x7ff0000f0)2 (0x7ff0000f4)0
(0x7ff0000f8)1 (0x7ff0000fc)0 (0x7ff000100)0
(0x7ff000104)0 (0x7ff000108)0 (0x7ff00010c)0
*/
/*
total heap usage: 0 allocs, 0 frees, 0 bytes allocated
*/
(0x7ff00010c + 4 - 0x7ff0000e0) / 4 = 12 = 4 * 3.
Исходная версия quasimoto, :
std::vector< std::vector< T> >
std::vector<std::vector<int>> xs = {{1, 2, 3}, {1, 2}, {1}, {}};
for (auto const& col : xs) {
for (auto const& el : col)
printf("(%p)%d ", &el, el);
puts("");
}
/*
(0x59f91d0)1 (0x59f91d4)2 (0x59f91d8)3
(0x59f9220)1 (0x59f9224)2
(0x59f9270)1
*/
/*
total heap usage: 7 allocs, 7 frees, 144 bytes allocated
*/
144/4 = 36, куда ему столько? :)
int xs[][4] = {{1, 2, 3}, {1, 2}, {1}, {}};
for (auto const& col : xs) {
for (auto const& el : col)
printf("(%p)%d ", &el, el);
puts("");
}
/*
(0x7ff0000d0)1 (0x7ff0000d4)2 (0x7ff0000d8)3 (0x7ff0000dc)0
(0x7ff0000e0)1 (0x7ff0000e4)2 (0x7ff0000e8)0 (0x7ff0000ec)0
(0x7ff0000f0)1 (0x7ff0000f4)0 (0x7ff0000f8)0 (0x7ff0000fc)0
(0x7ff000100)0 (0x7ff000104)0 (0x7ff000108)0 (0x7ff00010c)0
*/
/*
total heap usage: 0 allocs, 0 frees, 0 bytes allocated
*/
(0x7ff00010c + 4 - 0x7ff0000d0) / 4 = 16 = 4 * 4.