Is the stack address common to heap addresses?

I read. On most operating systems, addresses in memory start from the highest to the lowest. So I'm wondering if all the heap, stack, and global memory fall under the same order ..?

If I created ...

pointerType* pointer = new pointerType  //creates memory address 0xffffff

And then create a local variable on the stack

localObject object

there will be localObjects address 0xfffffe

Or the order of the heap and stack is completely different.

+3
source share
9 answers

memory addresses start from highest to lowest

Are the addresses of houses on your street from the highest to the lowest, or from the lowest to the highest? Well, it depends on how you drive.

, . ( , . ).

, , , , (, , ). , , , . , . , , , . , - , .

. , , . , ( "SP" ) - , .

. , . . . .

- . , . , , , .

, . . , . , .

. "" , , , , - , . , .

, , : "" ( ) ( ). , , - .

, , , , .

+2

.

+3

, , .

( ++) , ++.

+3

. , . , .

DSP ( ) - , (.. , , ). ; , , .

+2

, , :

(*) , , , , , (.data .bss) (.text), .

  • , x86 , , , , , .

- , .

. , , . , , . Atmel AVR , , ( ) , 16 24 ( ) .

8051 - . , , , , , . .

- /, . , , .

, , , -, . , , " " .

, , , - .

, , . , , . -, .

+2

pointerType* pointer = new pointerType //creates memory address 0xffffff

0xffffff. - -. , , , 0xffffff

+1

, . , , .

C , . , int: /int o "" . , ( ) , .

0

, . , , . , , . printf ( "0x% x\n", & variable), , . , , , , , , .

, , , - , , . , , StackOverflow .

0
source

Stack and heap are not mutually exclusive. Imagine these two hypothetical behind-the-scenes compiler implementations:

void PreMain()
{
    char initialHeap[initialHeapSize]
    HeapPointer heapHead = &initialHeap;
    ...
    int returncode = main(argc, argv);
    ...
}

void PreMain()
{
    void * stack = GetFromOSHeap(stackSize);
    // some assembly intrinsic to replace the stack pointer
    ...
    int returncode = main(argc, argv);
    ...
}

You may not find them in the main compiler, but I bet that the embedded system works like that there.

0
source

Source: https://habr.com/ru/post/1750697/


All Articles