static memory address (not C's "static")

Started by
7 comments, last by GameDev.net 19 years, 1 month ago
i need to have a variable (of unspecified size) at a certain memory location (ex 0x0AFF00C2) how can you do that without causing an access violation or corrupting another program? solutions are not limited to VC++, x86, or Windows
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)
Advertisement
Well on windows maybe you could try this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/virtualalloc.asp

Uhh, two more things... 1) This seems like kind of a strange thing to do, I hop you're not trying to get rid of a memory access violation this way :P. 2) A program cannot accidentally corrupt the memory of another program.
Quote:Original post by caesar4
i need to have a variable (of unspecified size) at a certain memory location (ex 0x0AFF00C2)


The only reasons I can think of for needing to write data to a particular memory location are in cases where the size is very definitely known. That's seriously low-level stuff. Your operating system might not even let you try it - and indeed, the real memory addresses are not what the program sees; the OS creates a virtual address space per process. (So if you were hoping to share data between programs like this, you're SOL.)
this is more of a dsp programming thing, not x86 and definatelly not win32
Cartman's definition of sexual harrasement:"When you are trying to have intercourse with a lady friend, and some other guy comes up and tickles your balls from behind"(watch South Park, it rocks)
If all you want to do is write a byte to location 0x0aff00c2 then you can use "*(char *)0x0aff00c2 = n;". Reading is similiar "n = *(char *)0x0aff00c2;"
-Mike
Anon Mike: I dare you to try that. [wink]. He specified that he doesn't want to corrupt another process's memory, therefore he must be running in some equivalent of x86 protected mode. (i.e. only having access to certain segments of the memory).


I had hoped that this (mmap) and this (also mmap) would be useful, but I doubt it now, since it refers to files.
It might help to know what you're trying to do caesar. Generally speaking, Anon Mike's method is the typical way to do it. If you're dealing with memory mapped hardware registers and you know the location of the reg and its size, by all means read and write to it... as long as you either aren't sitting on an OS that restricts hardware access to kernel processes, or you are and are writing a kernel mode process (or there is no OS at all).

Otherwise I can't imagine how else this might be useful. How often do you know the address of just any variable at compile-time anyway?
Quote:Original post by caesar4
this is more of a dsp programming thing, not x86 and definatelly not win32


Huh? Maybe you should have said that to begin with! "Not limited to Windows" means that you will be using it on windows, and maybe somewhere else too. If you want help, try being more specific about what you are trying to do, and on what platform. If you do not specify platform, people here will assume you're some kind of newbie talking about Windows development and answer accordingly. Now, what is it you're trying to do, on a higher level?

This topic is closed to new replies.

Advertisement