start to write up more of internals doc

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@330034 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Joe Watkins 2013-04-09 00:16:42 +00:00
parent fa5ef560a6
commit 177c88c1ca

View file

@ -1,9 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<sect1 xml:id="internals2.memory.persistence" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Data persistence</title>
<sect1 xml:id="internals2.memory.persistence" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Data persistence</title>
<simpara>
In the context of PHP, data persistence is taken to mean any data that is intended to survive the current request.
</simpara>
<simpara>
Persistence can be used, for example, to keep conntections to a database server for multiple requests, Zend provides a sub-api of its emalloc/efree mechanisms, predictably name pemalloc/pefree etc
</simpara>
<note>
<simpara>
All of the following functions take the additional persistent parameter, should this be false, Zend will use it's regular allocators and the memory should not be considered persistent. Where memory is allocated as persistent, system allocators are invoked, under most circumstances they are still not able to return NULL pointers just as the Main memory APIs.
</simpara>
</sect1>
</note>
<table xml:id="internals2.memory.management.papis">
<title>Persistent memory APIs</title>
<tgroup cols="2">
<thead>
<row>
<entry>Prototype</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><code>void *pemalloc(size_t size, zend_bool persistent)</code></entry>
<entry>Allocate <code>size</code> bytes of memory.</entry>
</row>
<row>
<entry><code>void *pecalloc(size_t nmemb, size_t size, zend_bool persistent)</code></entry>
<entry>
Allocate a buffer for <code>nmemb</code> elements of
<code>size</code> bytes and makes sure it is initialized with zeros.
</entry>
</row>
<row>
<entry><code>void *perealloc(void *ptr, size_t size, zend_bool persistent)</code></entry>
<entry>
Resize the buffer <code>ptr</code>, which was allocated using
<code>emalloc</code> to hold <code>size</code> bytes of memory.
</entry>
</row>
<row>
<entry><code>void pefree(void *ptr, zend_bool persistent)</code></entry>
<entry>
Free the buffer pointed by <code>ptr</code>. The buffer had to be
allocated by <code>pemalloc</code>.
</entry>
</row>
<row>
<entry>
<code>void *safe_pemalloc(size_t nmemb, size_t size, size_t offset, zend_bool persistent)</code>
</entry>
<entry>
Allocate a buffer for holding <code>nmemb</code> blocks of each
<code>size</code> bytes and an additional <code>offset</code> bytes.
This is similar to <code>emalloc(nmemb * size + offset)</code> but adds
a special protection against overflows.
</entry>
</row>
<row>
<entry><code>char *pestrdup(const char *s, zend_bool persistent)</code></entry>
<entry>
Allocate a buffer that can hold the NULL-terminated string
<code>s</code> and copy the <code>s</code> into that buffer.
</entry>
</row>
<row>
<entry>
<code>char *pestrndup(const char *s, unsigned int length, zend_bool persistent)</code>
</entry>
<entry>
Similar to <code>pestrdup</code> while the length of the
NULL-terminated string is already known.
</entry>
</row>
</tbody>
</tgroup>
</table>
<caution>
It is important to remember that memory allocated to be persistent is not optimized or tracked by the Zend engine; it is not subject to memory_limit.
</caution>
</sect1>