Jump to content
  • Advertisement
Sign in to follow this  
caesar4

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

This topic is 4912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Well on windows maybe you could try this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/memory/base/virtualalloc.asp

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.)

Share this post


Link to post
Share on other sites
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;"

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!