将写入时复制prevent数据复制的阵列? [英] Will copy-on-write prevent data duplication on arrays?

查看:98
本文介绍了将写入时复制prevent数据复制的阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编程在PHP的解析CSV数据到关联数组的Web API客户端,我想用这些数组时来保护我的用户数据复制。

I am programming a web API client in PHP that parses CSV data into associative arrays and I want to protect my users from data-duplication when using these arrays.

我的用户将永远不会被写入到这些阵列(理论上他们可以,但它使得在实践中没有意义)。

My users will never be writing to these arrays (theoretically they could but it makes no sense in practice).

现在我的问题是...如果我周围的用户通过这些数组参数的方法,将PHP的写入时复制机制prevent数据复制或将不明确接受一个参考的任何方法阵列接收阵列的完整副本?

Now my question is... if my users pass these arrays around as arguments to methods, will PHP's copy-on-write mechanism prevent data-duplication or will any method that doesn't explicitly accept a reference to an array receive a complete copy of the array?

推荐答案

写入时复制顾名思义手段没有变量被复制,直到事情是写的;只要不是一个字节在周围传递的变量发生变化时,PHP需要自动避免unnecesary重复的,并且无需使用显式引用由于这种机制的照顾。

Copy on write as the name suggests means no variable is being copied until something is written; as long as not a single byte is changed in the variable passed around, PHP takes care of avoiding unnecesary duplicates automatically and without the need of using explicit references thanks to this mechanism.

本文详细解释这是怎么在PHP源$ C ​​$ C实现,而作为文章建议,使用Xdebug的人们可以轻松地检查变量没有被复制的功能函数xdebug_debug_zval。

This article explains in detail how is this implemented in the source code of PHP, and as the article suggests, using xdebug one can easily check the variables are not being duplicated with the function xdebug_debug_zval.

此外这个答案这里因此具有更多的写入时复制。

Additionally this answer here on SO has more on Copy-on-Write.

这篇关于将写入时复制prevent数据复制的阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆