[comp.sys.amiga.tech] How do I find out how much stack space I have ??

gnn@ssibbs.UUCP (George Neville-Neil) (11/15/88)

[Eat hot death Line Eater...]

OK.  I am trying to find out a program's allocated Stack space.  
I wrote a simple little test program that does this....

	MyTask = FindTask(0);

	printf("%d\n",MyTask->tc_SPUpper);
	printf("%d\n",MyTask->tc_SPLower);
	printf("%d\n",MyTask->tc_SPReg);

It runs but no matter what I set the stack to (using the cli Stack command)
the SPUpper and SPLower numbers are always 4096 bytes apart.  SPReg does change
but not predictably.  

So what am I doing wrong ??  I need to do this to make sure that if the user
runs the program from the cli it will tell them to set the stack to 8000.

				Thanks In Advance....

				George Neville-Neil

P.s. Does anyone know where FindTask is documented ??  It is not in the EXEC
manual that I could see.

morgan@brambo.UUCP (Morgan W. Jones) (11/23/88)

In article <42@ssibbs.UUCP> gnn@ssibbs.UUCP (George Neville-Neil) writes:
>OK.  I am trying to find out a program's allocated Stack space.  

The first word (double word?) below the bottom of stack indicates the
stack's size.

>P.s. Does anyone know where FindTask is documented ??  It is not in the EXEC
>manual that I could see.

Try the Libraries manual page A-72.

-- 
Morgan Jones                                 morgan@hcr.UUCP
Human Computing Resources, Toronto, Canada
"BMATH - 6 months and counting ..."

bryce@cbmvax.UUCP (Bryce Nesbitt) (12/04/88)

In article <42@ssibbs.UUCP> gnn@ssibbs.UUCP (George Neville-Neil) writes:
>
>OK.  I am trying to find out a program's allocated Stack space.  
>I wrote a simple little test program that does this....

That won't do it.

The stack is different from CLI and Workbench.  If your compiler has
a global that gives the stack size, then use it.  Else:

/*
 * stack_test.c  27-Oct-87.  Bryce Nesbitt
 *
 */
#include "exec/types.h"
#include "exec/tasks.h"
#include "libraries/dosextens.h"
#include "stdio.h"
struct Process *FindTask();

void main()
{
register struct Process     *Process;
register FILE		    *Handle;
struct CommandLineInterface *CLI;

    if (!(Handle=fopen("con:0/11/250/128/Stack Window","a")))
	exit(20);       /* "a" is used so the window won't flicker */

    Process=FindTask(0L);

    if (CLI=(struct CommandLineInterface *)(Process->pr_CLI<<2))
	{
	if (CLI->cli_Background)
	    fprintf(Handle,"Background");
	else
	    fprintf(Handle,"Foreground");
	fprintf(Handle," CLI #%ld\n",Process->pr_TaskNum);

	fprintf(Handle,"Actual stack is: %ld\n\n",
	       CLI->cli_DefaultStack<<2);
	}
    else
	{
	fprintf(Handle,"This is not a CLI process\n");
	fprintf(Handle,"Actual stack is %ld\n\n",Process->pr_StackSize);
	}
    Delay(100L);    /* Be quick :-).  BTW: *Never* Delay(0L);! */
    fprintf(Handle,"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
		    /* Dramatic exit :-) */
    fclose(Handle);
}

ewhac@well.UUCP (Leo 'Bols Ewhac' Schwab) (12/06/88)

In article <5422@cbmvax.UUCP> bryce@commodore.COM (Bryce Nesbitt) writes:
:The stack is different from CLI and Workbench.  If your compiler has
:a global that gives the stack size, then use it.  Else:
:
:[ code ]
:	fprintf(Handle,"Actual stack is: %ld\n\n",
:	       CLI->cli_DefaultStack<<2);
:	}
:    else
:	{
:	fprintf(Handle,"This is not a CLI process\n");
:	fprintf(Handle,"Actual stack is %ld\n\n",Process->pr_StackSize);
:	}

	Say, Bryce, didn't we go around on this a while back?  As I recall,
the CLI, Process, and Task structures lie about how much stack you have.
The only reliable way to find out how much stack you have is to look at the
longword at the very top of the stack, which contains the stacksize.

	Finding the top of your stack is not obvious to me at the moment...

_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
Leo L. Schwab -- The Guy in The Cape	INET: well!ewhac@ucbvax.Berkeley.EDU
 \_ -_		Recumbent Bikes:	UUCP: pacbell > !{well,unicom}!ewhac
O----^o	      The Only Way To Fly.	      hplabs / (pronounced "AE-wack")
"Work FOR?  I don't work FOR anybody!  I'm just having fun."  -- The Doctor