
Define Clear Ownership Rules for Heap Memory in C Functions
Decide who frees every heap block in C by naming owners and borrowers, marking transfers in function contracts, and following a few conventions that stop leaks.
Tag
362 posts

Decide who frees every heap block in C by naming owners and borrowers, marking transfers in function contracts, and following a few conventions that stop leaks.

See how an I2C address byte is built, what ACK and NACK mean at each byte, why a slave holds SCL low, and how to avoid the 7-bit versus 8-bit mix-up.

Build a complete I2C client driver for a TMP102-style sensor on Linux 6.12: id tables, probe, SMBus reads, a sysfs attribute, device tree node and test output.

False sharing makes threads that write different variables slow each other down because they share a cache line. See it in a four-thread C counter.

Real-time means a bounded, predictable response to an event, not raw speed. Learn what determinism, deadlines and jitter mean and how an RTOS guarantees them.

Build a program that reads any number of integers from input, using malloc, calloc, realloc and free the right way, with the checks that prevent crashes.

Make a microcontroller a class-compliant USB MIDI device with TinyUSB: the 4-byte event packet, note and control change messages, and receiving from the host.

Control hyperfine 1.19 with --warmup, --prepare, --setup, --cleanup and --parameter-scan to measure cold and warm runs and sweep threads or compilers.

Move a NASM boot sector into 32-bit protected mode, set up a flat GDT and a stack, then call a freestanding C function that writes to VGA text memory.

Run a function at task level from a FreeRTOS interrupt with xTimerPendFunctionCallFromISR: arguments, config flags, failure modes and alternatives.

See where C variables live: the stack for locals that vanish on return, the heap for data you free yourself. Learn the limits, costs and bugs of each.

Run a USB CDC serial port on the ESP32-S3 native USB pins with esp_tinyusb in ESP-IDF 5, and know what happens to the built-in USB serial and JTAG.