Skip to content

Commit 2eab6ce

Browse files
committed
docs: moved reference counting to memory management
1 parent 493fae0 commit 2eab6ce

8 files changed

Lines changed: 54 additions & 14 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="refresh" content="0; url={{ redirect_url }}">
6+
<link rel="canonical" href="{{ redirect_url }}">
7+
<title>Redirecting&hellip;</title>
8+
<script>
9+
window.location.replace({{ redirect_url | tojson }} + window.location.hash);
10+
</script>
11+
</head>
12+
<body>
13+
<p>This page has moved to <a href="{{ redirect_url }}">its new location</a>.</p>
14+
</body>
15+
</html>

‎docs/source/conf.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,17 @@
6767
)
6868
html_theme_options = asdict(theme_options)
6969
pygments_style = 'sphinx'
70+
71+
72+
redirects = {
73+
'core/data-structures/reference-counting': '../memory-management/reference-counting.html',
74+
}
75+
76+
77+
def generate_redirects(_app):
78+
for source, target in redirects.items():
79+
yield source, {'redirect_url': target}, 'redirect.html'
80+
81+
82+
def setup(app):
83+
app.connect('html-collect-pages', generate_redirects)

‎docs/source/core/data-structures/index.md‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
# Data structures
1+
# Data Structures
22

33
```{toctree}
44
:hidden:
55
66
zval
7-
reference-counting
87
zend_string
98
zend_constant
109
```

‎docs/source/core/data-structures/zend_string.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ the strings length, along with some other fields. It looks as follows:
2222
};
2323
```
2424
25-
The `gc` field is used for {doc}`./reference-counting`. The `h` field contains a hash value, which is
26-
used for hash table lookups. The `len` field stores the length of the string in bytes, and the `val`
27-
field contains the actual string data.
25+
The `gc` field is used for {doc}`../memory-management/reference-counting`. The `h` field contains a hash value,
26+
which is used for hash table lookups. The `len` field stores the length of the string in bytes, and
27+
the `val` field contains the actual string data.
2828
2929
You may wonder why the `val` field is declared as `char val[1]`. This is called the [struct
3030
hack](https://www.geeksforgeeks.org/struct-hack/) in C. It is used to create structs with a flexible size, namely by allowing the last element
@@ -145,7 +145,7 @@ strings.
145145
146146
- - `zend_string_separate(s)`
147147
- Duplicates the string if the reference count is greater than 1. See
148-
{doc}`./reference-counting` for details.
148+
{doc}`../memory-management/reference-counting` for details.
149149
150150
- - `zend_string_realloc(s, l, p)`
151151
@@ -167,9 +167,9 @@ Programs use some strings many times. For example, if your program declares a cl
167167
`MyClass`, it would be wasteful to allocate a new string `"MyClass"` every time it is referenced
168168
within your program. Instead, when repeated strings are expected, php-src uses a technique called
169169
string interning. Essentially, this is just a simple `HashTable` where existing interned strings are
170-
stored. When creating a new interned string, php-src first checks the interned string
171-
buffer. If it finds it there, it can return a pointer to the existing string. If it doesn't, it
172-
allocates a new string and adds it to the buffer.
170+
stored. When creating a new interned string, php-src first checks the interned string buffer. If it
171+
finds it there, it can return a pointer to the existing string. If it doesn't, it allocates a new
172+
string and adds it to the buffer.
173173

174174
```c
175175

‎docs/source/core/data-structures/zval.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ member, but never both at the same time. However, it doesn't know which member i
6464
Remembering this is our job, and that's exactly what the `IS_*` constants are for.
6565

6666
The top members of `zend_value` mostly mirror the `IS_*` constants, with the exception of
67-
`counted`. `counted` polymorphically refers to any [reference-counted](reference-counting.md) value,
68-
including strings, arrays, objects, resources and references. `null` and `bool` are missing from
69-
`zend_value` because their types are self-contained.
67+
`counted`. `counted` polymorphically refers to any [reference-counted](../memory-management/reference-counting.md)
68+
value, including strings, arrays, objects, resources and references. `null` and `bool` are missing
69+
from `zend_value` because their types are self-contained.
7070

7171
The rest of the fields aren't important for now.
7272

@@ -112,7 +112,8 @@ intimidating at first. We'll go over it step by step.
112112
`zval.u1` stores the variable type, the given `IS_*` constant, along with some other flags. It's
113113
definition looks a bit complicated. You can think of the entire field as a 4 byte integer, split
114114
into 3 parts. `v.type` stores the actual variable type, `v.type_flags` is used for some
115-
[reference-counting](reference-counting.md) flags, and `v.u.extra` is pretty much unused.
115+
[reference-counting](../memory-management/reference-counting.md) flags, and `v.u.extra` is pretty
116+
much unused.
116117
117118
`zval.u2` defines some more storage for various contexts that is often unoccupied. It's there
118119
because the memory would otherwise be wasted due to padding, so we may as well make use of it. We'll
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Memory Management
2+
3+
```{toctree}
4+
---
5+
hidden: true
6+
---
7+
reference-counting
8+
```
9+
10+
This section describes how php-src manages the lifetime of allocated data.

docs/source/core/data-structures/reference-counting.md renamed to docs/source/core/memory-management/reference-counting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Reference counting
1+
# Reference Counting
22

33
In languages like C, when you need memory for storing data for an indefinite period of time or in a
44
large amount, you call `malloc` and `free` to acquire and release blocks of memory of some size.

‎docs/source/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ introduction/ides/index
1313
:hidden:
1414
1515
core/data-structures/index
16+
core/memory-management/index
1617
core/output-buffering
1718
```
1819

0 commit comments

Comments
 (0)