Memory Layout and Class Design:Define an object Foo which is an empty class. Explain its memory layout.
After defining an empty class Foo, what is the minimum size of this class in memory and why?
Adding Members:
Modify Foo to contain exactly one int variable. Describe the updated memory layout. In function stack, heap, or static storage duration.
How does adding an int member affect the alignment and padding of the class?
String Handling:
https://chatgpt.com/share/c4dfd43c-15f6-4201-a318-7dde06c8e5e0
Background
In this interview, we aim to assess the candidate's proficiency in advanced memory management and optimization techniques in C++. The focus will be on their ability to implement and use custom memory allocators in the STL, manage memory pools, understand and exploit memory models and alignment for performance, and apply advanced garbage collection techniques.
Interview Questions
Task 1: Custom Allocators in STL
Question: Implement a custom allocator for an STL container, such as std::vector, that allocates memory from a pre-allocated memory pool.
We define the arena's shared interface, which is following the cppreference: https://en.cppreference.com/w/cpp/memory/allocator
突發奇想,讓 GPT 來決定什麼問題是困難的問題,看看我有沒有辦法都達成。
畢竟身為平常沒事就看 Cppreference 與 C++ 各版標準的人,我對 GPT 能問出的問題有十分的信心可以完成。
於是參閱 GPT 認為困難的問題:
https://chat.openai.com/share/10bbc2b3-9791-49b3-9957-f0a51843c126
Understood. Let's delve into more challenging and nuanced aspects of C++ programming, going beyond RAII and basic range-based for loops and iterators.
Advanced Memory Management and Optimization:Custom allocators in STL: Implementing and using allocators for specialized memory management.
Intrusive containers and their advantages in performance-sensitive contexts.Note: This does not seem to fit the "follow-up" structure. We request that ChatGPT revise this item.
Interview Question: Expression Templates and Compile-Time Polymorphism
Background:
Expression templates are a C++ template metaprogramming technique used for optimizing high-performance computations, particularly in numerical computing and scientific applications. They enable the efficient evaluation of complex expressions by eliminating unnecessary temporaries and combining multiple operations into a single loop at compile time.
Task:
Implement a Simple Vector Class:Create a template class Vector that encapsulates a dynamic array of elements (use std::vector for storage).
Implement basic operations like element access and size retrieval.
using K = key_type;
using T = value_type;
class config_base {
config_base() {}
public:
virtual T get(const K) = 0;
virtual void set(const K, const K) = 0;
};
上面文章總說改天介紹,這邊就是改天介紹的 todo list
或者讀者想看什麼樣的議題,也可以補充在這邊
SignatureDefault type in C89a = malloc(1024)
ABI issue
Itanium C++ ABI
RTTI (should I put it here?)
pimpl idiom