Go To Memory

It looks like the code is very simple. There is a loop, and the structure X is defined in it. Note that it is defined two times differently:

  1. A link to it is created, and the p field is immediately initialized in it.

  2. First, the structure is created, and only then the p field is written.

It would seem that it should work the same way. Let’s apply the acquired knowledge and run escape analysis.

The i2 variable has gone hip. Why is this and what might it affect?

Here’s what. This is how the benchmark piece of code looks like when we immediately initialize the p field:

It can be seen that 0.2 ns was spent.

And this is how a piece of code looks like when, after initializing the structure itself, we initialize some field:

We invite you to Saint Highload++ 2022 – a conference of developers of high-load systems, which will be held on September 22-23 in St. Petersburg. Schedule published. Tickets can be booked here.

Similar Posts

Leave a Reply