Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of replication Mechanism when Writing in PHP

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Xiaobian to share with you the sample analysis of the copy-time mechanism in PHP, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

What is Copy On Write?

Answer: When copying an object, it is not really copying the original object to another location in memory, but setting a pointer in the memory mapping table of the new object, pointing to the location of the source object, and setting the Copy-On-Write bit of that block of memory to 1. In this way, when reading the new object, the memory data does not change, and the read operation is directly executed; When writing to a new object, copy the real object to the new memory address, modify the memory mapping table of the new object to point to the new location, and write to the new memory location.

This technique needs to be used in conjunction with virtual memory and paging, and the advantage is that when performing a copy operation, it is not a real memory copy, but only a pointer, thus greatly improving efficiency. But this is not always true, and if most of the objects need to continue writing after copying new objects, it will generate a lot of paging errors, which is not worth it. So COW is efficient when writing to only a small number of pages after copying new objects.

In the PHP kernel, the copy-on-write mechanism is also used to avoid memory increase during assignment. For example, when we use foreach loop body, we can find the mystery. Example code:

$m1 = memory_get_usage();

$str=

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report