C++ Study Questions#

  • What are some common examples of undefined behavior?
    • What is memory corruption?
      • What are some common causes of it?
    • How can you get UB without memory corruption?
    • How does UB interact with optimization?
  • What is RAII? How does it differ from garbage collection?
  • Why use smart pointers instead of raw pointers?
  • What is the STL?
    • What is it useful for?
    • What are some common STL collections?
    • What are some common STL algorithms?
    • How do iterators work?
    • Why can’t you dereference the end iterator?
  • What is the difference between “value semantics” and “reference semantics”?
  • What is “type erasure”?
    • How is std::function implemented?
    • How is std::any implemented?
      • What does std::any even do?
  • Why does an empty struct have a size of 1 and not 0?
  • What is std::atomic?
    • How does it differ from volatile?
    • How can it be optimized?
  • What are the versions of the C++ standard?
    • What major features were added in each of them?
  • What are the major C++ compilers?
    • Under what licensing terms are they available?

C++ Performance#

  • What are some common compiler optimizations?
    • What are some optimizations a compiler cannot do?
    • What are downsides to having the compiler do optimizations?
  • Why are virtual function calls slower?
  • What parts of a codebase need most optimizing?
    • What parts do not?
  • Common compiler flags
    • What is the difference between -O2, -O3 and -Os?
    • What is -g?
      • Why is it normally combined with -O0?
        • What does -O0 do?
        • How is that different from what -g does?
  • What is the difference between throughput and latency?

Operating System Questions#

  • What is the difference between the stack and the heap?
  • What is an operating system kernel?
    • What are some examples of operating system kernels?
    • What is “kernel” or “supervisor” mode?
    • What is a monolithic kernel vs a microkernel?
    • What is a driver?
      • Can they run in usermode?
        • When?
  • What is a system call?
    • What is the difference between a blocking and non-blocking system call?
  • What is the difference between a process and a thread?
    • What are the performance implications?
  • Describe different forms of IPC
    • What is the difference between brokered and non-brokered IPC?
    • What considerations should you take into account when choosing an IPC system?
  • Describe virtual memory.
    • What is an address space?
    • What is memory protection?
    • What is paging?
      • What is a page fault?
    • What does a kernel have to do to implement virtual memory?
    • How does a program allocate more memory on the stack?
    • How does a program allocate more memory on the heap?
      • In userspace?
      • What syscalls might it have to make?
    • How do memory mapped files work?
      • When should you prefer this to read and write syscalls?
    • How does shared memory work?
      • When should you prefer this to other forms of IPC?
    • What is swap?
    • What is a TLB?
      • What performance implications does it have?

Network Study Questions#

  • Explain the layers of the OSI model
    • How do they map to Internet-based protocols?
  • Explain IP basics
    • What is IP?
    • What is an IP address?
      • What is a subnet?
      • What is a non-routable IP address?
      • What is localhost?
        • When would we use it?
      • What is NAT?
        • When is it used?
    • How does IP relate to link-level protocols?
      • Give some examples of link-level protocols.
      • Explain CSMA/CD.
      • What is MTU?
      • Explain Path MTU Discovery, and why it’s important.
    • What is ICMP?
      • What are 2 command-line utilities that use it?
      • Why is it important?
    • What is the difference between a hub, a switch, and a router?
    • What is the difference between IPv4 and IPv6?
  • Explain DNS basics
    • What is DNS?
    • What are some types of DNS records?
    • On Unix
      • What is /etc/hosts?
      • What is /etc/resolv.conf?
      • What sort of things can go wrong if these are configured incorrectly?
    • How do you access DNS from your applications?
  • What is a VPN?
  • Explain the basics of TCP.
    • How does TCP implement reliability on top of IP?
    • TCP is stream-oriented, UDP is packet-oriented. What does this mean?
    • Explain the TCP three-way handshake.
      • What are SYN cookies?
    • How do TCP acknowledgements work?
      • How does TCP handle the lack of negative acknowledgements?
    • What is the TCP window size?
  • Explain the basics of UDP.
    • What are some differences between TCP and UDP?
    • Why might you want to use UDP?
    • How are UDP broadcasts implemented?
  • On Linux, what sort of things can you tune about networking using sysctl?
    • Why might you want to do this?
  • Why are heartbeats important?
    • Why might they be implemented in user protocols?
      • Why is TCP keepalive not enough?

Network Programming Practice Projects#

  • Echo server
    • Can test by hand using netcat
    • v1: Accepts single TCP connection, echos all inputs
    • v2: Use threading to accept multiple connections, echo each to itself
    • v3: Use single-thread
      • select or epoll syscall
      • async in Rust
      • Network reactor/dispatcher library in C++
  • Chat server
    • Accept multiple connections
    • Can test by hand using netcat
    • v1: Send all whole lines (requires buffering) to all clients
      • No length restriction
    • v2: Handshake to set username
      • Make still it still is testable using netcat
      • Server sends username along with messages
  • File server
    • Simple HTTP-like protocol to specify filename of what file to send
      • Make sure you sanitize for inputs!
    • v1: Serve one static file at a time
    • v2: Stream multiple files to multiple clients without using threads
    • v3: Support uploads
      • Write custom client
  • Exchange
    • v1: Just exchange connection
      • Keep order books
        • When new order comes in compatible with old order, make trade
        • One security at first, then multiple
          • But build multiple into protocol right away
      • TCP Protocol:
        • Create a custom protocol with CLI client
        • Client -> Server
          • Orders
            • Only GTC limit orders at first
            • Quantity
            • Security
            • Price
            • Buy/Sell
            • Order ID
              • Why is this useful?
        • Server -> Client
          • Order confirmation
            • All order information, echoed
          • Trade confirmation (when orders match)
            • Also indicate whether client was maker or taker
    • Add-ons
      • Add heartbeats to protocol
      • Market data
        • UDP broadcast
        • Current state of order books
      • Drop copy
        • Separate TCP records of all trades
        • Record trades in file before confirming
        • Allow replay of previous days’ trades
      • Fees and kickbacks
        • Charge takers
        • Reimburse makers
        • Configurable on by-security basis
      • Credit limits
      • Advanced order types
        • IOC/FOK
        • Maker-only orders
      • FX-style last look
      • SSL support