Postblit
Explore the concept of postblit in D programming to understand how object copying works beyond simple bit-wise copying. Learn to properly implement postblit functions to handle reference types like slices, ensuring each copied object has its own independent data. Understand how to disable postblit to prevent copying when necessary.
We'll cover the following...
We'll cover the following...
What is “postblit”?
Copying is constructing a new object from an existing one. Copying involves two steps:
- Copying the members of the existing object to the new object bit-by-bit. This step is called blit, short for block transfer.
- The second step is making further adjustments to the new object after the block transfer. This step is called postblit.
The first step is handled automatically by the compiler, which copies the members of the existing object to the members of the new object:
auto returnTripDuration = tripDuration; // copying
Do not confuse ...