Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would you find out if a machine’s stack grows up or down in memory? (JAVA)

Tags:

java

c

I have a C program to check whether the machine stack is growing up or down in memory in.

It goes like that :

#include <stdio .h>

void sub(int *a) {
 int b;

 if (&b > a) {
    printf("Stack grows up.");
 } else {
    printf("Stack grows down.");
 }
}

main () {
 int a;
 sub(&a);
}

Now i want to do the same in Java. :-)

Any one knows a solution without writing any native code ???

Thanks

like image 700
Roman Avatar asked Jul 22 '09 08:07

Roman


1 Answers

If you're not doing any native code, then I can't imagine a situation where it could possibly matter in pure Java code. After all, the Java stack might be allocated in any direction at all instead of being a strictly contiguous block of memory (like the machine stack).

like image 161
Greg Hewgill Avatar answered Nov 15 '22 18:11

Greg Hewgill