Saltar al contenido ForoHackers

Memory management: start here

Gestión de memoria
#3381 · · Citar · Denunciar

Memory management is how a computer and its software hand out, track and take back memory. It spans hardware translation of addresses, the operating system's paging and the allocator inside a program. Most crashes, leaks and security holes in low-level code come from getting it wrong, so understanding it pays off in every language.

Key concepts

  • Virtual memory: each process has its own address space, translated to physical pages by the hardware and the kernel.
  • Paging: memory moves in fixed-size pages, with page tables, a TLB and page faults that load pages on demand.
  • Stack and heap: the stack holds call frames and grows automatically; the heap holds data that outlives a call.
  • Allocators: malloc and similar libraries carve the heap into blocks and must limit fragmentation.
  • Reclamation: manual freeing, reference counting, ownership rules or a garbage collector decide when memory returns.

Vocabulary

  • Page fault: an access to a page not currently mapped, which the kernel resolves or rejects.
  • Fragmentation: free memory split into pieces too small to use.
  • Leak: memory no longer needed but never released.
  • Use after free: touching memory after it has been given back.

What to study, in order

  1. The address space of a process: print where code, stack and heap live.
  2. Pointers and manual allocation in C, with a leak and a use-after-free that you cause and catch with a sanitizer.
  3. Write a simple allocator: a free list, then splitting and coalescing blocks.
  4. Page tables and the TLB, from a computer architecture text, drawn by hand.
  5. Watch a process's memory use grow and swap with the system's monitoring tools.

Related tags

#kernels #c #rust #computer-architecture #debugging

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder