Why is the stack address lower than that of heap in Visual C++? -


as know, stack address higher heap addresses in process address space. when wrote program verify in vs2010, got trouble.the stack has address lower heap, lower of data segment. program shown follows:

#include "stdafx.h" #include "malloc.h" static int g_a=123; int g_b=123; int main() {     static int a=123;     int b=123;     float c[10]={0};     int *p1=(int*)malloc(sizeof(int));     int *p2=(int *)malloc(5*sizeof(int)); } 

here address according vs2010:

&g_a    0x01097038  &g_b    0x0109703c &a      0x01097040  &b      0x002af7a8 c       0x002af778  p1      0x00571500 p2      0x00571540 

obviously, pointer p1 , points array on heap, has bigger address &b, on stack. that's why?

ps:sorry absence of picture due poor reputation, or describe question more clearly.

"as know, stack address higher heap addresses in process address space."

your assumption here false. stack , heap both allocated process's virtual address space , may, intents , purposes, located practically anywhere in address space.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -