468,544 Members | 1,735 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,544 developers. It's quick & easy.

printing an address with Write function

2
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
Oct 7 '08 #1
4 1275
JosAH
11,448 Expert 8TB
Why does printf("%p", your_pointer) mess around in the heap?

kind regards,

Jos
Oct 7 '08 #2
TuRu87
2
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).
Oct 7 '08 #3
JosAH
11,448 Expert 8TB
What happens if you first execute "free(malloc(4096))" first?

kind regards,

Jos
Oct 7 '08 #4
donbock
2,422 Expert 2GB
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?
Oct 8 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Stephen Briley | last post: by
42 posts views Thread by Prashanth Badabagni | last post: by
42 posts views Thread by junky_fellow | last post: by
7 posts views Thread by salmonella | last post: by
57 posts views Thread by Robert Seacord | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.