The aim of this page📝 is to learn SICP in public. I will publish my notes as I go. Maybe reduntant. But I'm blogging mainly for myself, for the imagined community. No AI as a writing assistant (yes AI a way to talk to text_books), just a morning routine of keyboard, teacher, Anki Notes and a small deep work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| high address ┌────────────┐ | |
| │ stack │ ← grows downward, per-thread | |
| │ ↓ │ | |
| │ (gap) │ | |
| │ ↑ │ | |
| │ heap │ ← grows upward, shared across threads | |
| │────────────│ | |
| │ BSS │ uninitialised globals | |
| │ data │ initialised globals | |
| │ text │ code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| thread-1 stack thread-2 stack | |
| │ │ | |
| ▼ ▼ | |
| [frame A] [frame X] | |
| │ │ | |
| └──► heap ◄────────┘ | |
| [obj-1][obj-2][obj-3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void create_typist(int uses_nvim) { | |
| int wpm = 150; | |
| char name[4] = {'p', 'a', 'u', 'l'}; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Lower Address <--------------------------------------------------------> Higher Address | |
| *<pointer> | |
| +----------+-----------+-----------+---------+---------+---------+---------+----------+ | |
| | <return> | uses_nvim | wpm | name[0] | name[1] | name[2] | name[3] | ... | | |
| +----------+-----------+-----------+---------+---------+---------+---------+----------+ | |
| | ... | 1 | 150 | 'p' | 'a' | 'u' | 'l' | ... | | |
| +----------+-----------+-----------+---------+---------+---------+---------+----------+ | |
| | 0xFEFC | 0xFF00 | 0xFF04 | 0xFF08 | 0xFF0C | 0xFF10 | 0xFF14 | 0xFF18 | | |
| +----------+-----------+-----------+---------+---------+---------+---------+----------+ | |
| \____________________________________________________________________________________/ |
| Type | Size |
|---|---|
| char | 1 |
| unsigned char | 1 |
| signed char | 1 |
| short | 2 |
| unsigned short | 2 |
| int | 2,4 |
| unsigned int | 2,4 |
| long | 4,8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdlib.h> | |
| #include <stdio.h> | |
| int main() { | |
| int *p = (int *)malloc(sizeof(int)); // allocate on heap | |
| *p = 42; | |
| printf("%d\n", *p); | |
| free(p); // must always free | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| heap (graph of pointers) wire (flat byte sequence) | |
| [obj-A] ──ptr──► [obj-B] | |
| └──ptr──► [obj-C] →→→ [ A | B | C | ... ] | |
| virtual addresses no addresses, just values | |
| process-local portable, self-contained |
| Year | Milestone |
|---|---|
| 1957 | FORTRAN — static allocation only, no heap |
| 1960 | LISP — first language with dynamic allocation + GC |
| 1960 | ALGOL 60 — introduced stack frames as a formal concept |
| 1966 | DRAM invented by Robert Dennard at IBM |
| 1972 | C — direct control via malloc()/free() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # include <stdio.h> | |
| int* dangerous() { | |
| int x = 42; | |
| return &x; | |
| } | |
| int main() { | |
| int* p = dangerous(); | |
| printf("print pointer of dangerious: %d\n", *p); |
NewerOlder