-3

I am into reading reading a article talking about allocating space for pointers that does not say exactly what the PROGRAM BREAK" is but mentions it. I need to know what the program break is. If I create say a pointer to a memory space with malloc..ie

char *ptr = (char*)malloc(100);

is the PROGRAM BREAK the beginning or the end? Is it the ADDRESS of p[0] or p[99] THX

ShadowRanger
  • 143,180
  • 12
  • 188
  • 271
  • 2
    The "program break" (which is controlled by [`brk` and `sbrk`](http://man7.org/linux/man-pages/man2/sbrk.2.html)) isn't really used these days. It's mostly of historical interest now. – Some programmer dude Feb 11 '18 at 22:05
  • @Someprogrammerdude Unless you are implementing your own memory allocator. – DYZ Feb 11 '18 at 22:12

1 Answers1

0

Well, the program break is the end of the initialized data segment, and, as such, it is in general elsewhere:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

int main() {
    char *ptr = (char*)malloc(100);
    printf("%p %p %p\n", ptr, ptr+100, sbrk(0));
    return 0;
}

Output:

0x744010 0x744074 0x765000

The actual value depends on the strategy used by the runtime memory allocator (aka malloc).

DYZ
  • 55,249
  • 10
  • 64
  • 93