[Python-Dev] stack check on Unix: any suggestions? (original) (raw)

M.-A. Lemburg mal@lemburg.com
Tue, 29 Aug 2000 22:39:18 +0200


Fredrik Lundh wrote:

... or maybe the optimizer removed your buffer variable? try printing the buffer address, to see how much memory you're really consuming here. printf("%p %d\n", buffer, depth);

I got some more insight using:

int checkstack(int depth) { if (depth <= 0) return 0; checkstack(depth - 1); }

int recurse(int depth) { char stack[2048]; char *heap;

memset(stack, depth % 256, sizeof(stack));
heap = (char*) malloc(2048);

/* Call recursively */
printf("stack %p heap %p depth %d\n", stack, heap, depth);
checkstack(depth);
recurse(depth + 1);
return 0;

}

main() { recurse(0); }

This print lines like these: stack 0xbed4b118 heap 0x92a1cb8 depth 9356

... or in other words over 3GB of space between the stack and the heap. No wonder I'm not seeing any core dumps.

-- Marc-Andre Lemburg


Business: http://www.lemburg.com/ Python Pages: http://www.lemburg.com/python/