-2

could anybody please tell me if Data segment is the same as Heap segment, if not, could you please explain what's the difference between the two, i understand what's the difference between stack and heap, but in some books they evoke data segment as a separate elemet, thank you for your help !!!

camelkos
  • 51
  • 5

1 Answers1

0

Imagine a stack of containers. These containers can be taken off or put on. They contain values. When you run a program, the computer can predetermine how many containers there are, and when to put them on and take them off. This is a stack.

Now imagine a massive shelf, with millions upon millions of slots. This shelf can have containers in it, but is completely arbitrary. There is no organization, and you can freely take containers out and put containers in blocks at a time. This is the heap.

If you know about stack and heap, you probably know about pointers, too. If you need any clarification on those, a pointer is a container in the stack that has an address somewhere in the heap. From that pointer, you can find locations around the pointer. If you increase the pointer, you can look at addresses farther along in the heap. This is how arrays work.

0x1a4
  • 111
  • 6