Memory location
3 answers
Assuming you are on a system with no secure memory access and / or no MMU, so the addresses used are true physical addresses, this is really easy.
#include <stdio.h>
#include <stdlib.h>
/* Print memory contents from <start>, 16 bytes per line. */
static void print_memory(const void *start, size_t len)
{
const unsigned char *ptr = start;
int count = 0;
printf("%p: ", ptr);
for(; len > 0; --len)
{
printf("%02X ", *ptr++);
if(++count >= 16)
{
printf("\n%p: ", ptr);
count = 0;
}
}
if(count > 0)
putchar('\n');
}
int main(void)
{
print_memory(NULL, 1024);
return EXIT_SUCCESS;
}
This should work fine for example. old Amiga , but little used on modern PCs running Linux, Windows, etc.
+6
source to share
The question is a bit vague.
You either want to map all the memory, which won't work (at least not easy) due to the mapping and replacement.
Or you want to map a portion of the allocated memory. It's easy. You can create a pointer to memory and map all the corresponding bytes. Or, if you know the layout, you can create a structure. Either way, you need to know where the end is. Knowing the size or separator symbol.
+2
source to share