โ† All CPP Flashcard Decks

Memory Management & Performance Optimization Flashcards

6 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 6 Memory Management & Performance Optimization flashcards as text
  1. What is the purpose of a memory-mapped file?

    Answer: Mapping a file's contents directly into a process's address space for fast file I/O

    Memory-mapped files allow a file to be accessed as if it were an array in memory, enabling very fast reads and writes via virtual memory mechanisms.

  2. What is the difference between strong and weak references in managed memory environments?

    Answer: Strong references prevent garbage collection; weak references allow the GC to collect the object if no strong references exist

    Strong references keep an object alive; weak references let the garbage collector reclaim the object when memory pressure is high.

  3. What does it mean to 'benchmark' code?

    Answer: Measuring the performance of code under controlled, repeatable conditions

    Benchmarking measures execution time, memory usage, or throughput of code segments to compare implementations or track regressions.

  4. What is the purpose of an allocator in systems programming?

    Answer: Managing how memory is requested from the OS and distributed to program objects

    An allocator implements strategies for carving up memory from the OS and handing it out to program requests (malloc/new).

  5. What is branch prediction and why does it impact CPU performance?

    Answer: A CPU optimization that guesses the outcome of conditional branches to execute instructions speculatively

    CPUs use branch prediction to speculatively execute code ahead of resolving a branch, and mispredictions cause costly pipeline flushes.

  6. What is the role of a just-in-time (JIT) compiler in performance?

    Answer: Compiles bytecode to native machine code at runtime, allowing optimizations based on actual execution patterns

    JIT compilation bridges the performance gap between interpreted languages and native code by compiling hot code paths at runtime with profile-guided optimizations.