problemscpp
A collection of my answers to algorithm problems in c++.
set_stack_limit.cpp
浏览该文件的文档.
1#if defined(linux)
2#include <iostream>
3#include <sys/resource.h>
4
5int set_stack_limit(int stack_size) {
6 rlim_t kStackSize = stack_size;// min stack size = 16 MB
7 struct rlimit rl {};
8
9 int result = getrlimit(RLIMIT_STACK, &rl);
10 if(result == 0 && rl.rlim_cur < kStackSize) {
11 rl.rlim_cur = kStackSize;
12 result = setrlimit(RLIMIT_STACK, &rl);
13 if(result != 0) {
14 std::cerr << "setrlimit returned result = " << result << std::endl;
15 }
16 }
17 return result;
18}
19#else
20int set_stack_limit(int /*stack_size*/) { return 0; }
21#endif
int set_stack_limit(int)