调整任务堆栈大小

linux下任务堆栈可以在/etc/security/limits.conf中控制每个进程打开文件描述符的最大数量和堆栈数量,重启后生效;在/etc/sysctl.conf中控制系统打开最大文件描述符的数量fs.file-max,sudo sysctl -p生效

最大堆栈设置不合理,数组过大(比如400M)会产生错误,设置正确后运行正常

windows下加编译参数

-Wl,–stack=1677721600 (1600M)



以下代码在windows跑会崩溃
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
auto find(int a);
auto find(unordered_map<int, string> &obj, int key)
{
     
	return obj.find(key);
}
auto push(int a, stack<int> &b)
{
     
	return b.push(a);
}
int main(void)
{
     
	char graph_buffer[1024 * 1024 * 400];
	unordered_map<int, string> c;
	auto iter = c.equal_range(1);
	cout << boolalpha;
	cout
		<< (iter.first == iter.second);
	string a = "1234";
	string b = a;
	a.erase(0, 1);
	cout << a << endl;
	cout << b << endl;
	cout << (b == string("1234")) << endl;
	pair<int, string> tmp1(1, "123");
	pair<int, string> tmp2(1, "456");
	c.insert(tmp1);
	//auto p = c.find(1);
	auto p = find(c, 1);
	if (p != c.end())
	{
     
		cout << c.erase(p->first) << endl;
		c.insert(tmp2);
	}
	cout << c.erase(456) << endl;
	for (auto a = c.begin(); a != c.end(); a++)
	{
     
		cout << a->first << ":" << a->second << ";";
	}
	cout << c.count(1) << endl;
	stack<int> d;
	push(1, d);
	cout << endl;
	cout << d.top();
}

加了编译参数后则正常运行

g++ 52.cpp -o 52 -Wl,--stack=1677721600

结果:
true234
1234
true
1
0
1:456;1

1

你可能感兴趣的:(windows,c++,gcc/gdb编译调试)