An application is given a range of memory by the OS. Generally, the application has to request the memory but that functionality may be obscured to the programmer because of the language.
Languages like C allow for block requests for specific sizes, whereas other languages like C++, C#, and Java allow for requests through the use of keywords like new
. Each language has a number of ways to allocate memory, so this is just a brief overview. Releasing the memory back to the OS may either be done explicitly or through a garbage collector.
Accessing the memory within the application depends upon how it was allocated. C and C++ are the best known for using the concept of pointers to indicate / track where the memory is located. Otherwise, memory access is handled through the class or variable that was created.
Most of the time, you don't have to worry about specific memory access within your program. The language constructs and OS effectively obscure that concern for you.
Your example of a timer in a game is a great example of where you wouldn't need to worry about the underlying memory allocation. You'll have a variable representing the timer, and you'll just read from the variable.
My answer is relevant for when you are writing the application, whereas zxcdw's answer is relevant for accessing memory that belongs to another application. Your LMGTFY terms would be "debugging" and "reverse-engineering" to delve further into that topic.
Some additional reading:
- The Wikipedia article on Computer Memory will give you a decent overview of things.
- Then look into the Wikipedia article on Memory-mapped I/O to get a deeper understanding of the machinations that go on.
- Finally, look at the article on Virtual Memory to get a better answer for how each OS will handle memory mapping a little bit differently than the others.