Gyh's Braindump

Where Storage Lives

tags
Programming Language Concept
source
DT-On Java 8

Registers

  • fastest: inside CPU
  • limited Numbers
  • typically no direct control over register allocation

Stack

  • lives in genral random-access memory (RAM)
  • direct support from the processor via stack pointer
  • fast and efficient way to allocate storage

Heap

  • pool of memory, also lives in RAM
  • technically slower than stack when allocating and releasing memory
    • overheads
      • find unused chunks with required space
      • bookkeeping mappings of chunks and addresses passed to caller

Constant storage

  • placed directly in the program code -> safe
  • in some special cases, some constants can be placed in other special locations
    • string literals in Java

Non-RAM storage

Turn objects into something exist on the other medium, and yet be resurrected into a regular RAM-based object when necessary.

  • serialized objects #serialization turn objects intio streams of bytes, usually used when sending objects to another machine

  • persistent objects place objects on disk