Skip to content

Instantly share code, notes, and snippets.

View pkutaj's full-sized avatar

pavol kutaj pkutaj

View GitHub Profile
@pkutaj
pkutaj / sicp-home.md
Last active June 4, 2026 21:38
SICP learning notes index
@pkutaj
pkutaj / tmpjdiff2xv.txt
Created May 26, 2026 07:21
Explaining The Heap snippet
high address ┌────────────┐
│ stack │ ← grows downward, per-thread
│ ↓ │
│ (gap) │
│ ↑ │
│ heap │ ← grows upward, shared across threads
│────────────│
│ BSS │ uninitialised globals
│ data │ initialised globals
│ text │ code
@pkutaj
pkutaj / tmphs3t9ngh.txt
Created May 26, 2026 07:21
Explaining The Heap snippet
thread-1 stack thread-2 stack
│ │
▼ ▼
[frame A] [frame X]
│ │
└──► heap ◄────────┘
[obj-1][obj-2][obj-3]
@pkutaj
pkutaj / tmpbo_pb9oc.c
Created May 26, 2026 07:21
Explaining The Heap snippet
void create_typist(int uses_nvim) {
int wpm = 150;
char name[4] = {'p', 'a', 'u', 'l'};
}
@pkutaj
pkutaj / tmpym0r7t5p.txt
Created May 26, 2026 07:21
Explaining The Heap snippet
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 |
+----------+-----------+-----------+---------+---------+---------+---------+----------+
\____________________________________________________________________________________/
@pkutaj
pkutaj / tmpx2bcppq7.md
Created May 26, 2026 07:21
Explaining The Heap snippet
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
@pkutaj
pkutaj / tmpv8jkh6ht.c
Created May 26, 2026 07:21
Explaining The Heap snippet
#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;
}
@pkutaj
pkutaj / tmp4q5emzyh.txt
Created May 26, 2026 07:21
Explaining The Heap snippet
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
@pkutaj
pkutaj / tmpzmefups9.md
Created May 1, 2026 23:18
CTJ47_Why_a_Stack snippet
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()
@pkutaj
pkutaj / tmpenkv6pc_.c
Created May 1, 2026 23:18
CTJ47_Why_a_Stack snippet
# include <stdio.h>
int* dangerous() {
int x = 42;
return &x;
}
int main() {
int* p = dangerous();
printf("print pointer of dangerious: %d\n", *p);