Skip to content

Commit abfa1c0

Browse files
committed
test
1 parent 2261f3a commit abfa1c0

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

test/problems/hellounix/submissions/run_time_error/test-memsize_512.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,26 @@ using namespace std;
1313

1414
const size_t mb = 513;
1515

16+
template<typename T>
17+
T use(std::vector<T>& todo) {
18+
// init with some data
19+
for (std::size_t i = 0; i < todo.size(); i++) todo[i] = T(i % 7);
20+
// do some computation that needs the memory
21+
for (int k = 0; k < 7; k++) {
22+
for (std::size_t i = 0; i < todo.size(); i++) {
23+
std::size_t j = (i + todo[i]) % todo.size();
24+
todo[j] = (todo[i] % 7) + (todo[j] % 7);
25+
}
26+
}
27+
// accumulate the result
28+
T res = 0;
29+
for (auto x : todo) res = (res >> 1) + (x >> 1);
30+
return res;
31+
}
32+
1633
int main() {
17-
std::cerr << "Trying to allocate at least: " << 513 << " MB" << std::endl;
18-
vector<char> v(513 * 1024 * 1024);
19-
std::cerr << "Allocated: " << (v.end() - v.begin()) << " MB" << std::endl;
34+
std::cerr << "Trying to allocate at least: " << mb << " MB" << std::endl;
35+
vector<char> v(mb * 1024 * 1024);
36+
std::cerr << "Allocated: " << mb << " MB (" << use(v) << ")" << std::endl;
2037
return 0;
2138
}

0 commit comments

Comments
 (0)