-
Notifications
You must be signed in to change notification settings - Fork 0
Computer Memory
Do computers have memory like humans do? Well, sort of, but not really.
Imagine a city. In that city there many streets, and each street will have many buildings. Each building will have an address of some sort, which is a way to locate that specific building.
Every computer has memory. This memory is like the city we just talked about. Memory has cells (like our city has buildings) which holds some data(like buildings have things inside), namely a series of 1's and 0's because that is what computers understand. Each cell inside of the memory has a certain unique address(just like each building in a city has a unique address). If you know the address of a cell of memory then you can access what that cell's data is(just like if you know the address of a building, you can go inside and look around).
Well, so what? Why should I care about memory and cells and addresses? Here's why.
When you run your program(let's say you hit the "Run" button in Processing), your program is loaded into memory. All of the functions and variables you wrote and stored at multiple addresses for your computer to use. But, how does your computer know how much memory to set aside for your program. Think about our city we were walking about before. If you have a lot of stuff and it doesn't fit into a certain building, maybe you need to split up your stuff and put it into different buildings. Sure, humans can make a decision like that, but computers can't. If you computer had to decide what building all your stuff would go in, it would just crash; it can not make decisions like that. Computers NEED humans to tell them what to do.(if you have not done so, I would suggest reading the "Intelligence of Computers" wiki page).
Let's go back to talk about our program now. If your program won't fit inside of one single cell of memory(which it won't, trust me) then where will your computer put it? How many cells of memory will your computer decide to use. If it uses too few cells then the program won't work. If it uses too many cells, your program will work, but all the other stuff you have running on your computer won't work. So now we have a dilemma here. How do we tell our computer to use just the right number of memory cells?
Well, we have a fancy word for that, data types. Data types allow us to control how much memory our variables, functions, and programs take up. There are five main data types. They are: integer, float, double, character, and boolean. They each have a purpose, and they each take up different amounts of memory. Integer allows you to store whole numbers, such as 1, 8, 3, or any other number you can think of up to around 65,000. Float and double allow you to use numbers with a decimal point, so you can store the numbers 2.0, 3.1, 8.5, and so on. Unfortunately, Processing doesn't use the double data type, and so you have to stick with using float for decimals. Character allows you to store a single letter, such as "a", "v", "h", and so on. Boolean allows you to store either the word "true" or "false"(we'll get to boolean stuff later). Here's a table to help you out:
| Data Type Name | Name in a Program | Values It Can Handle | Amount of Memory |
|---|---|---|---|
| Integer | int | 0 through 2,000,000,000 | 32 bits |
| Float | float | 0 through 3,400,000,000,000,000,000,000,000,000,000,000,000,000 | 32 bits |
| Boolean | boolean | 1 or 0 | 1 bit |
| Character | char | all letters and symbols | 16 bits |
*a bit is the smallest unit of memory. a bit has a value of 0 or 1.