By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,483 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,483 IT Pros & Developers. It's quick & easy.

printing an address with Write function

P: 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
Share this Question
Share on Google+
4 Replies


Expert 10K+
P: 11,448
Why does printf("%p", your_pointer) mess around in the heap?

kind regards,

Jos
Oct 7 '08 #2

P: 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

Expert 10K+
P: 11,448
What happens if you first execute "free(malloc(4096))" first?

kind regards,

Jos
Oct 7 '08 #4

Expert 100+
P: 2,398
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.