Is there a simple way to view the memory? like so?
Code:0012FF64: 36 E8 76 3B B8 FF 12 00 26 24 41 00 01 00 00 00 6.v;..↕.&$A.....
Is there a simple way to view the memory? like so?
Code:0012FF64: 36 E8 76 3B B8 FF 12 00 26 24 41 00 01 00 00 00 6.v;..↕.&$A.....
If you have access to it, yes. Good luck with that under XP or any protected mode operating system.
You can look at memory you have allocated or have been given access to. Since poking around in another processes memory is really not how well-behaved programs work, XP for one, won't grant you access to any memory location you want.
Yes. If you allocated the memory, the OS will let you access it. That's why you allocate it in the first place.
Code:mytype * ptr; //ptr is some sort of integer that holds an address in memory. ptr = new mytype; //"new mytype" is a function that asks the OS for some memory // to hold a "mytype", sets up the memory and then returns the address. //So now ptr contains that address. std::cout << ptr << std::endl; //will display the address that we just spoke about std::cout << *ptr << std::endl; //will go to that address and tell cout to display the object there //(Hopefully you told cout previously what to do with it)
"If you tell the truth, you don't have to remember anything"
-Mark Twain
ok so i tried to convert it to using "printf()"
But it only displays the memory address? should i be using something other than "%p" ?Code:printf("%p",*ptr);
%p means "print a pointer."Code:printf("%p",*ptr);
*ptr is not a pointer. *ptr is (hopefully) some kind of object (which could be a pointer, but I doubt that's what you meant).
Think of it this way:
Remember that every pointer is an address.
" * " means "value at address"
" & " means "the address of"
So.... if you want to print the number 67... How could we finish this code so it does?
Code:int* a; int b = 67; a = /*What should I set it to?*/; std::cout << *a << std::endl;
Last edited by CodeMonkey; 08-01-2007 at 12:01 AM. Reason: more
"If you tell the truth, you don't have to remember anything"
-Mark Twain
ok, i get that... But even when i change it to
i still only get the address of the pointer, is it possible get thisCode:printf("%p",&ptr);
using printf()? or dose it have to be done using cout?Code:0012FF64: 36 E8 76 3B B8 FF 12 00 26 24 41 00 01 00 00 00 6.v;..↕.&$A.....
You can do it however you like. The question is: Do you have access to that memory?
Code:const int size = 16; char data[size]; //let's see what that looks like -- not having initialized the data printf("%X: ", &data[0]); for(int x = 0; x < size; ++x) printf("%X ",data[x]); printf(" "); //now I would treat data as a string, but we don't know where //the null character is! for(int y = 0; y < size; ++y) printf("%c",data[y]); //and that should do it
*edit* Interesting. When I ran that on my computer, some of the chars were displayed as much bigger than a char. How does printf() know that the hexadecimal arguments are chars?
Last edited by CodeMonkey; 08-01-2007 at 12:19 AM. Reason: more
"If you tell the truth, you don't have to remember anything"
-Mark Twain
>How does printf() know that the hexadecimal arguments are chars?
Cast to unsigned char first, which is promoted to unsigned int.
Code:for(int x = 0; x < size; ++x) printf("%X ", (unsigned char) data[x]);