printing an address with Write function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TuRu87
    New Member
    • Oct 2008
    • 2

    printing an address with Write function

    Hello,

    So I'm trying to create a malloc function and want to print some addresses to check on them and be able to visualize a little what's going on but I can't use printf cause it messes around my process's heap which I don't want.
    I was wondering how I could use the write function to print an address recovered from a pointer.
    Thanks
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Why does printf("%p", your_pointer) mess around in the heap?

    kind regards,

    Jos

    Comment

    • TuRu87
      New Member
      • Oct 2008
      • 2

      #3
      because it uses the malloc from the standard library. In fact when I execute the following code:

      printf("%p\n", sbrk(0));
      printf("%p\n", sbrk(0));

      I get:

      0x804979c
      0x804c000

      Which means that when the 1st printf is executed the 'break' indicating the end of the heap is moved (I think).

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        What happens if you first execute "free(malloc(40 96))" first?

        kind regards,

        Jos

        Comment

        • donbock
          Recognized Expert Top Contributor
          • Mar 2008
          • 2427

          #5
          Originally posted by TuRu87
          because it uses the malloc from the standard library. In fact when I execute the following code:

          printf("%p\n", sbrk(0));
          printf("%p\n", sbrk(0));

          I get:

          0x804979c
          0x804c000

          Which means that when the 1st printf is executed the 'break' indicating the end of the heap is moved (I think).
          What sort of behavior caused you to instrument your code like this?

          Comment

          Working...