0、起因
有的时候,DFS总是比BFS受人喜爱——毕竟DFS简单粗暴多了,而且有些东西用BFS去做无从下手,DFS是看起来可行的选择……
但是有个问题,DFS默认直接写入系统栈,系统栈又够浅的,这个时候OI常规手法是写手工栈,acm党有的时候也会想起来研究一下旁门左道——开栈外挂。
Uva上的神贴(Set heap size and stack size in C++,http://acm.uva.es/board/viewtopic.php?f=14&t=16685)里面提到了一个拓栈外挂:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main2() {
char test[255 << 20];
memset(test, 42, sizeof(test));
printf(":)\n");
return 0;
}
int main() {
int size = 256 << 20; // 256Mb
char *p = malloc(size) + size;
asm("movl %0, %%esp\n"
"pushl $exit\n" // if you get a compile error here under mingw/cygwin,
"jmp main2\n" // replace exit with _exit, and main2 with _main2.
:: "r"(p));
}
可惜这个外挂有点老了(kuangbin神牡丹江被虐哭),我们需要根据现在的实际环境与时俱进,学习新姿势,学会灵活运用拓栈挂了
事先声明:我汇编是为了研究这个问题现学现卖的,有什么地方讲的不对还望各位指正,谢谢!
1