Online Book Reader

Home Category

Professional C__ - Marc Gregoire [504]

By Root 1246 0
on.

Use new and delete instead of malloc() and free().

Use new[] and delete[] for arrays.

If you have an array of pointers to objects, you still need to allocate memory for each individual pointer and delete the memory — the array allocation syntax doesn’t take care of pointers.

The existence of memory allocation problem detectors, such as Valgrind, to expose memory problems

Smart pointers and specifically the new C++11 std::shared_ptr and std::unique_ptr, and why you should not use the old std::auto_ptr

Use std::make_shared() to create a std::shared_ptr.

Types of Questions

Find-the-bug questions often contain memory issues, such as double-deletion, new/new[] mix-up, and memory leaks. When you are tracing through code that makes heavy use of pointers and arrays, you should draw and update the state of memory as you process each line of code. Even if you see the answer right away, it will let the interviewer know that you’re able to draw the state of memory.

Another good way to find out if a candidate understands memory is to ask how pointers and arrays differ. At this point, the differences may be so tacit in your mind that the question catches you off-guard for a moment. If that’s the case, skim Chapter 21 again for the discussion.

When answering questions about memory allocation, it’s always a good idea to mention the concept of smart pointers and their benefits for automatically cleaning up memory or other resources. You definitely should also mention that it’s much better to use STL containers like std::vector instead of C-style arrays because the STL containers handle memory management for you automatically.

CHAPTER 22: MULTITHREADED PROGRAMMING WITH C++

Multithreaded programming is becoming more and more important with the release of multicore processors for everything from servers to consumer computers. Even the latest smartphones have multicore processors. An interviewer might ask you a couple of multithreading questions. C++11 includes a standard threading library, so it’s a good idea to know how it works.

Things to Remember

Race conditions and deadlocks and how to prevent them

The atomic types and atomic operations for possible lock-free programming

std::thread to spawn threads

The concept of mutual exclusion, including the usage of the different mutex and lock classes, to provide synchronization between threads

Condition variables and how to use them to signal other threads

What futures and promises are

Copying and rethrowing of exceptions across thread boundaries

Types of Questions

Since the multithreading library is only available since C++11, you don’t need to expect detailed questions, unless you are interviewing for a specific multithreading programming position.

An interviewer might ask you high-level questions, such as asking you to explain the general concepts behind multithreaded programming. This is a very broad question but allows the interviewer to get an idea of your multithreaded knowledge.

CHAPTER 23: MAXIMIZING SOFTWARE ENGINEERING METHODS

You should be suspicious if you go through the complete interview process with a company, and the interviewers do not ask any process questions — it may mean that they don’t have any process or that they don’t care about it. Alternatively, they might not want to scare you away with their process behemoth.

Source code control is also an important aspect of any development process.

Most of the time, you’ll get a chance to ask questions regarding the company. We suggest you consider asking about engineering processes and source code control solutions as one of your standard questions.

Things to Remember

Traditional life-cycle models

The tradeoffs of formal models, such as the Rational Unified Process

The main principles of Extreme Programming

Scrum as an example of an agile process

Other processes you have used in the past

Principles behind source code control solutions

Types of Questions

The most common question you’ll be asked is to describe the process that your previous employer used. When answering, you should mention

Return Main Page Previous Page Next Page

®Online Book Reader