Dive into C++ Object Memory Layout with Examples

In the previous article Analysis of C++ Process Coredump Problem Caused by Missing Bazel Dependencies, due to the use of different versions of proto objects in the binary, inconsistent object memory layouts led to memory address chaos when reading and writing members, ultimately causing the process to crash. However, we didn’t delve into the following questions at that time:

  1. How are objects laid out in memory?
  2. How do member methods obtain the addresses of member variables?

These actually involve the C++ object model. The book “Inside the C++ Object Model” comprehensively discusses this issue and is well worth reading. However, this book is not easy to read, and some content can be difficult to fully understand without practice even after reading. This article attempts to start from practical examples to help everyone gain an intuitive understanding of C++ class member variables and functions in memory layout, which will make it easier to understand this book later.

Read More

Analysis of Coredump Caused by Missing Bazel Dependencies

Recently, I encountered a strange coredump problem in a project, and the troubleshooting process was not smooth. After continuous analysis, I found a reproducible step, and through reasonable guessing and careful verification, I finally located the cause.

C++ coredump Bazel dependency missing

Looking back, I found that this type of coredump problem is indeed rare and not easy to troubleshoot. It’s only possible when the project code compilation dependency management is not very reasonable. Additionally, during the review process, I gained a better understanding of the coredump and C++ object memory distribution here. So I’ve organized an article, and if there are any errors, please feel free to point them out.

Read More

Why You Should Start Using AI as Soon as Possible

Many years from now, when people recall 2023, they might only remember it as the year ChatGPT and various large language models were born - the first year of artificial intelligence!

You must start using ChatGPT and other large language models as soon as possible

Read More