-
-
Notifications
You must be signed in to change notification settings - Fork 128
Edits to Complexity sprint 1 #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5aa1ece
4f36399
6d11097
0fce2a6
2a85ccf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,12 @@ | ||
| +++ | ||
| title = "Memory consumption" | ||
| description="Memory is finite" | ||
| time = 30 | ||
| emoji = "🥪" | ||
| [build] | ||
| render = 'never' | ||
| list = 'local' | ||
| publishResources = false | ||
| time = 30 | ||
| emoji= "🥪" | ||
| [objectives] | ||
| 1="Quantify the memory used by different arrays" | ||
| +++ | ||
|
|
@@ -19,7 +19,7 @@ Think back to Chapter 7 of <cite>How Your Computer Really Works</cite>. | |
|
|
||
| ```mermaid | ||
| graph LR | ||
| CPU -->|️ Fastest: Smallest| Cache -->|Fast: Small| RAM -->|Slow : Big| Disk -->|Slowest: Vast| Network | ||
| CPU -->|️ Fastest and Smallest| Cache -->|Fast and Small| RAM -->|Slow and Big| Disk -->|Slowest and Vast| Network | ||
| ``` | ||
|
|
||
| At each stage there are **limits** to **how fast** you can get the data and **how much** data you can store. Given this constraint, we need to consider how much memory our programs consume. | ||
|
|
@@ -34,11 +34,14 @@ const userRoles = ["Admin", "Editor", "Viewer"]; //An array of 3 short strings | |
| const userProfiles = [ {id: 1, name: "Farzaneh", role: "Admin", preferences: {...}}, {id: 2, name: "Cuneyt", role: "Editor", preferences: {...}} ]; // An array of 2 complex objects | ||
| ``` | ||
|
|
||
| Different kinds of data have different memory footprints: | ||
| Different kinds of data have different memory footprints. All data is fundamentally stored as bytes. We can form intuition for how much memory a piece of data takes: | ||
|
|
||
| - Numbers or booleans use less memory than objects | ||
| - Numbers are typically stored as 8 bytes. In some languages, you can define numbers which take up less space (but can store a smaller range of values). | ||
| - Each character in an ASCII string takes 1 byte. More complex characters may take more bytes. The biggest characters take up to 4 bytes. | ||
| - The longer a string, the more bytes it consumes. | ||
| - Objects and arrays need memory for their internal organisation _as well_ as the data itself. | ||
| - Objects and arrays are stored in different ways in different languages. But they need to store _at least_ the information contained within them. | ||
| - This means an array of 5 elements will use _at least_ as much memory as the 5 elements would on their own. | ||
| - And objects will use _at least_ as much memory as all of the _values_ inside the object (and in some languages, all of the keys as well). | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, is this a bit too much info? We don't want to overload them.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe... Let's maybe have a chat about it? I changed it because the previous content is kind of misleading - in most compiled programming languages, arrays and objects take exactly as much space as their contents/members/fields, so I wanted to avoid instilling an intuition that they have overhead where they don't necessarily...
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, it's a good point. I was trying to steer away from the python size of debacle I've encountered before with trainees and have oversteered. |
||
|
|
||
| More complicated elements or more properties need more memory. It matters what things are made of. All of this data added up is how much _space_ our program takes. | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH I had intended these just as a visual, that's why I rm the examples - but if you want them, I'm ok with this