memory dump

closed account (zwA4jE8b)
Hi guys, I am playing around with reading memory.

I have the following code, the output is a lot of numbers. I am wondering how to interpret the significance, if any, of those numbers. My first instinct is to read the numbers in pairs and convert that number to hex, but that is just a guess. Can anyone enlighten me as to what path I should take from here.

What I understand about this is that the program is reading 1000 characters backwards through the memory from where p is created.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{

unsigned char *p;
int i;
p = new unsigned char;

	for(i = 1000; i > 0; --i)  //1000 is an arbitrary number, could be anything.
	{
		cout << static_cast<unsigned>(p[i]) << " ";
	}
cout << endl;
cin.get();
}


So really all I would like to know is there any validity to the output of this, or is it just going to be useless?

Thank you.
Last edited on
you only allocate enough memory for one char, if you want to read 1000 characters you'll need to allocate space for 1000

unsigned char* p = new unsigned char[1000];

you're also not filling the memory with anything btw
Notice:
- you never allocated a dynamic array
- you are reading locations which you are not supposed to

If you output a space after p[i] you'll see how the digits should be broken
Topic archived. No new replies allowed.