← Hudson River Trading Interview Insights
I started talking about the allocation failing and they just waited.
Start by clarifying the context: is this a 64-bit process on a modern OS with virtual memory? Then explain the role of virtual memory, demand paging, and overcommit. Finally, discuss the consequences: thrashing, OOM killer, or allocation failure, depending on OS and configuration.
Pro tip: Mention that on Linux with overcommit enabled, malloc may succeed but the OOM killer may terminate the process later; on Windows, the allocation may fail immediately. This shows awareness of OS-specific behavior.
Ask about the OS, architecture (32-bit vs 64-bit), and whether the program uses malloc or mmap. This determines the behavior.
Describe how the OS provides virtual address space, allowing a process to request more memory than physical RAM. The 8 GB request is for virtual memory, not physical.
Explain that physical pages are allocated on demand when accessed. Overcommit policies (e.g., Linux overcommit_memory) determine if the allocation succeeds even if RAM+swap < 8 GB.
If overcommit is allowed, the process may run until physical memory is exhausted, causing thrashing or the OOM killer. If not, the allocation fails immediately (e.g., malloc returns NULL).
Highlight the trade-offs: overcommit improves utilization but risks OOM; strict accounting avoids OOM but may cause allocation failures. Mention swap space's role.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
I went straight to 'it hints the compiler to inline the function body' and they pushed back immediately.
Start by defining the modern purpose of inline (enabling multiple definitions across translation units and hinting at inlining), then discuss the trade-offs: code bloat, potential instruction cache pressure, and the fact that compilers often ignore the hint. Conclude by noting that inline is now primarily used for ODR compliance in headers, not performance.
Pro tip: Mention that inline is essential for defining functions in headers without violating the One Definition Rule (ODR), and that compilers today make inlining decisions based on optimization heuristics, not the keyword. This shows you understand both the language standard and real-world compiler behavior.
Explain that inline serves two roles: as a hint to the compiler to expand the function at the call site, and as a linkage specifier allowing multiple definitions across translation units.
Note that the performance hint is largely obsolete; compilers inline aggressively regardless. The primary modern use is to avoid ODR violations when defining functions in headers.
Cover code bloat, increased compile times, potential instruction cache misses, and the fact that inlining can be counterproductive if overused.
Suggest using inline for small, frequently called functions in headers, and relying on compiler flags (e.g., -O2) for performance. Avoid forcing inline on large functions.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.