STACK_MAX is the literal end of the memory reserved for the stack, used for assertions like STACKTOP < STACK_MAX. STACKTOP is the current top of the stack.
Any pointer between STACK_BASE and STACK_MAX is on the stack (and ptr > STACK_MAX in that example, since it is not). On Mon, Sep 14, 2015 at 12:57 AM, awt <[email protected]> wrote: > Hi, > > I am currently porting some code now that requires me to know if the > memory of a pointer is allocated on the heap or the stack. Is there an API > in Emcripten that allows me to do this? I tried to do this using the > STACK_BASE and STACK_MAX javascript variables but didn't manage to get very > far. The following is my code: > > bool isStackAddress() > { > void* ptr = malloc(5 * sizeof(int)); > > int result = EM_ASM_INT( { > console.error('STACK_BASE: ' + STACK_BASE + ' STACKTOP: ' + > STACKTOP + ' STACK_MAX:' + STACK_MAX + ' ptr: ' + $0); > return 1; // return dummy result > }, ptr); > return result; > } > > But this is what I observed when I ran the function: > STACK_BASE = 61904 > STACKTOP = 61904 > STACK_MAX = 5304784 > ptr = 5318696 > > I had expected ptr to be bigger than STACK_BASE + STACK_MAX (5366688) but > apparently this is not the case. Is there a better way or existing API in > Emscripten that identifies if a chunk of memory is allocated on the stack > or heap? Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
