2020-02-15 20:01:48 +00:00
|
|
|
I64 Recurse(I64 n)
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
if (n)
|
2020-12-23 23:27:18 +00:00
|
|
|
return 1 + CallStackGrow(0x800, 0x1000000, &Recurse, n - 1);
|
2020-02-20 23:40:10 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
I64 Recurse2(I64 n)
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
if (n)
|
2020-12-23 23:27:18 +00:00
|
|
|
return 1 + Recurse2(n - 1);
|
2020-02-20 23:40:10 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
I64 Recurse3(I64 n, I64 lo, I64 hi)
|
2020-02-15 20:01:48 +00:00
|
|
|
{
|
2020-12-23 23:27:18 +00:00
|
|
|
if (lo <= n < hi)
|
|
|
|
return 1 + Recurse3(n - 1, lo, hi);
|
2020-02-20 23:40:10 +00:00
|
|
|
else if (n)
|
2020-12-23 23:27:18 +00:00
|
|
|
return Recurse3(n - 1, lo, hi);
|
2020-02-20 23:40:10 +00:00
|
|
|
else
|
|
|
|
return 0;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
#define DEPTH (2 * 1024 * 1024)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
2020-02-16 01:19:05 +00:00
|
|
|
U0 StackGrowDemo()
|
2020-02-15 20:01:48 +00:00
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
F64 t0;
|
|
|
|
|
2020-12-23 23:27:18 +00:00
|
|
|
t0 = tS;
|
|
|
|
"%X:%X\n", DEPTH, Recurse(DEPTH);
|
|
|
|
"Time:%7.5fs\n", tS - t0;
|
2020-02-20 23:40:10 +00:00
|
|
|
|
|
|
|
//If you know the max stack ahead of time...
|
|
|
|
//Recurse2's stack is 16 because you have 1 arg,
|
|
|
|
//a return addr and no local variables.
|
2020-12-23 23:27:18 +00:00
|
|
|
t0 = tS;
|
|
|
|
"%X:%X\n", DEPTH, CallStackGrow(DEPTH * 16 + 0x800, DEPTH * 16 + 0x800, &Recurse2, DEPTH);
|
|
|
|
"Time:%7.5fs\n", tS - t0;
|
2020-02-20 23:40:10 +00:00
|
|
|
|
|
|
|
//$LK,"CallStackGrow",A="MN:CallStackGrow"$() works with multiple args.
|
2020-12-23 23:27:18 +00:00
|
|
|
t0 = tS;
|
|
|
|
"%X:%X\n", DEPTH, CallStackGrow(DEPTH * 32 + 0x800, DEPTH * 32 + 0x800, &Recurse3, DEPTH, 1000, 2000);
|
|
|
|
"Time:%7.5fs\n", tS - t0;
|
2020-02-15 20:01:48 +00:00
|
|
|
}
|
|
|
|
|
2020-02-16 01:19:05 +00:00
|
|
|
StackGrowDemo;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
|
|
//Be careful because you can fragment memory.
|