- Variables
- Using Variables
- Understanding Your Computer's Memory
- C# Data Types
- Numeric Variable Types
- Literals Versus Variables
- Constants
- Reference Types
- Summary
- Q&A
- Workshop
Understanding Your Computer's Memory
If you already know how a computer's memory operates, you can skip this section. If you're not sure, read on. This information is helpful to understanding programming.
What is your computer's RAM used for? It has several uses, but only data storage need concern you as a programmer. Data is the information with which your C# program works. Whether your program is maintaining a contact list, monitoring the stock market, keeping a budget, or tracking the price of snickerdoodles, the information (names, stock prices, expense amounts, or prices) is kept within variables in your computer's RAM when it is being used by your running program.
A computer uses random access memory (RAM) to store information while it is operating. RAM is located in integrated circuits, or chips, inside your computer. RAM is volatile, which means that it is erased and replaced with new information as often as needed. Being volatile also means that RAM "remembers" only while the computer is turned on and loses its information when you turn the computer off.
A byte is the fundamental unit of computer data storage. Each computer has a certain amount of RAM installed. The amount of RAM in a system is usually specified in megabytes (MB), such as 32MB, 64MB, 128MB or more. One megabyte of memory is 1,024 kilobytes (KB). One kilobyte of memory consists of 1,024 bytes. Thus, a system with 8MB of memory actually has 8_1,024KB, or 8,192KB of RAM. This is 8,192KB_1,024 bytes for a total of 8,388,608 bytes of RAM. Table 3.1 provides you with an idea of how many bytes it takes to store certain kinds of data.
Table 3.1 Minimum Memory Space Generally Required to Store Data
Data |
Bytes Required |
The letter x |
2 |
The number 500 |
2 |
The number 241.105 |
4 |
The phrase Teach Yourself C# |
34 |
One typewritten page |
Approximately 4,000 |
The RAM in your computer is organized sequentially, one byte following another. Each byte of memory has a unique address by which it is identifiedan address that also distinguishes it from all other bytes in memory. Addresses are assigned to memory locations in order, starting at 0 and increasing to the system limit. For now, you don't need to worry about addresses; it's all handled automatically.
Now that you understand a little about the nuts and bolts of memory storage, you can get back to C# programming and how C# uses memory to store information.