Memory allocation
Memory allocation is the process of reserving or assigning storage for program data and objects during execution.
Refactoring to Rust
Memory allocation is the process of reserving and managing regions of computer memory for program data.
- How it is used
- Connects routine value storage and cleanup to Rust performance choices and host–WebAssembly data exchange.
- How deep it goes
- Defines allocation and deallocation, compares stack with heap, and shows an exported allocator; stops short of a complete reclamation procedure.
- Examples
- Uses a welcome program with alternative `free(name)` placements and a Rust function returning a pointer to Wasm memory.
- What you can do after
- Evaluate/understand where values are stored and cleaned up, and apply a Rust allocation function to a Wasm host–module interface.
Latency
Dynamic memory allocation is reserving and releasing storage during program execution from a runtime-managed memory region.
- How it is used
- Identifies runtime storage work to examine when reducing latency in performance-sensitive code.
- How deep it goes
- Explains heap requests, free-list search, splitting, and reuse through a simplified allocator, while noting that real allocators have additional layers.
- Examples
- Uses a Rust `Box` allocation, a free-list diagram, and measured recursive, memoized, and iterative Fibonacci implementations.
- What you can do after
- Diagnose/debug with it by benchmarking latency-sensitive code and checking whether eliminating dynamic allocation removes useful work.
100 Go Mistakes and How to Avoid Them
Memory allocation is the process of reserving memory for data or runtime objects.
- How it is used
- Uses allocation behavior to diagnose Go performance costs and decide when reducing heap allocations is worthwhile.
- How deep it goes
- Explains stack frames, heap escapes, and their costs through contrasting functions and benchmarks, then gives allocation-reduction options.
- Examples
- Contrasts `sumValue` with `sumPtr`, reports their allocations per operation, and shows compiler output identifying an escape.
- What you can do after
- Diagnose/debug with it by checking compiler escape decisions and benchmark allocation counts before changing code.
Read how 100 Go Mistakes and How to Avoid Them explains memory allocation →
Code Like a Pro in Rust
Memory allocation is the process of reserving memory regions for data during program execution.
- How it is used
- Guides choices between stack values, heap-backed Rust data structures, and custom or allocation-free approaches.
- How deep it goes
- Explains heap and stack behavior, then implements allocators through required trait methods, defaults, and layout concerns.
- Examples
- Uses `Box`, `Vec`, and `String` values alongside pass-through and C-backed allocator implementations.
- What you can do after
- Build it from scratch: implement a custom allocator for `Vec`, while checking unsafe operations and layout requirements.
Read how Code Like a Pro in Rust explains memory allocation →
Modern C
Dynamic allocation is obtaining and releasing object storage during program execution rather than solely at translation or function-entry time.
- How it is used
- Handles growing collections and irregular data by reclaiming storage during program execution.
- How deep it goes
- Explains allocation functions, sizing, void pointers, lifetime tracking, and invalid release cases, but defers complete initialization rules.
- Examples
- Uses a large vector of doubles, sizeof-based sizing, allocation-release pairs, and realloc as concrete illustrations.
- What you can do after
- Operate/configure storage with malloc, calloc, realloc, aligned_alloc, and free while avoiding leaks and invalid releases.
Rust in Action: Systems programming concepts and techniques
Memory allocation is the process of reserving memory for data or program execution.
- How it is used
- Uses dynamic allocation to explain how programs obtain more memory and why heap use can affect performance.
- How deep it goes
- Explains request-use-release, allocator mediation, and stack–heap trade-offs, then measures timings without implementing an allocator.
- Examples
- Measures heap-object creation in a graphical particle program and plots allocation size against duration with gnuplot.
- What you can do after
- Diagnose/debug with it by recording allocation timings, plotting them, and considering whether fewer heap allocations would help.
Read how Rust in Action: Systems programming concepts and techniques explains memory allocation →
Go by Example
A memory allocation is a reservation of heap memory made during program execution, commonly counted per operation in performance measurements.
- How it is used
- Measures and reduces heap work while profiling Go code paths such as URL generation, argument parsing, result handling, and response reading.
- How deep it goes
- Explains profiling, benchmark comparison, escape-analysis output, and practical allocation trade-offs without detailing garbage-collector internals.
- Examples
- Uses URL string construction, a config flag parser, Result values in concurrent processing, and io.ReadAll on HTTP response bodies.
- What you can do after
- Diagnose/debug with pprof, benchmark memory metrics, benchstat, and compiler escape-analysis output to target unnecessary allocations.
Fast Python: High performance techniques for large datasets
- How it is used
- Uses memory accounting and compact representations to reduce storage pressure and make room for parallel or in-memory processing.
- How deep it goes
- Builds an iterative object-size estimator and explains identity tracking, but notes that external allocations may remain inaccessible.
- Examples
- Compares NOAA station files stored as lists of byte values with files read directly as bytes.
- What you can do after
- Build it from scratch by writing an iterative estimator that tracks object identities and separates container overhead from content.
Read how Fast Python: High performance techniques for large datasets explains memory allocation →
Modern C, Third Edition
Dynamic allocation is a runtime mechanism that obtains storage for objects independently of ordinary declarations and releases it according to allocation operations.
- How it is used
- Supports growing collections, variable user input, large matrices, interaction graphs, and other data whose size changes at runtime.
- How deep it goes
- Explains storage creation, failure handling, specialized allocation functions, initialization, and release, while deferring fuller lifetime rules.
- Examples
- Uses a runtime-sized double vector, explicit element initialization, malloc failure checks, and eventual free.
- What you can do after
- Operate malloc-family functions to obtain, initialize, resize, and release runtime-sized storage while checking failure.
Read how Modern C, Third Edition explains memory allocation →
PostgreSQL Mistakes and How to Avoid Them
Memory allocation is the assignment of available memory resources to database processes and operations.
- How it is used
- Uses PostgreSQL workload testing to expose unsafe per-query memory settings under high concurrency.
- How deep it goes
- Explains shared_buffers, per-plan-node work_mem multiplication, concurrency, parallel execution, and OOM recovery consequences.
- Examples
- Uses 100-client and 1000-client pgbench runs, configuration listings, workload output, and Linux OOM logs.
- What you can do after
- Diagnose memory pressure with pgbench and system logs, then avoid allocating excessive work_mem.
Read how PostgreSQL Mistakes and How to Avoid Them explains memory allocation →
Python Workout: 50 ten-minute exercises
Memory allocation is the process of reserving storage for data during program execution.
- How it is used
- Frames memory allocation as background knowledge for understanding list growth and investigating optimization problems.
- How deep it goes
- Explains spare list capacity and inspection with sys.getsizeof, but stops short of allocator internals or garbage-collector control.
- Examples
- Demonstrates repeated list appends, sys.getsizeof measurements, and output showing stepwise storage increases.
- What you can do after
- Evaluate list storage growth with sys.getsizeof and recognize when allocation details matter for optimization.
Read how Python Workout: 50 ten-minute exercises explains memory allocation →
Related concepts
- execution context stackcontrasts with · An execution context stack is a runtime last-in-first-out structure that records active function or method calls and their execution state and return information.
- system calluses · A system call is an operating-system interface through which a user-space program requests a service or operation from the kernel.
- memory allocatorpart of · A software component or interface that manages the allocation and release of memory for program use.
- vectorused by · A vector is an ordered, indexed sequence of elements, often numerical, represented as a mathematical quantity or a computational collection.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.










