| OLD | NEW |
| 1 .. highlightlang:: c | 1 .. highlightlang:: c |
| 2 | 2 |
| 3 | 3 |
| 4 .. _memory: | 4 .. _memory: |
| 5 | 5 |
| 6 ***************** | 6 ***************** |
| 7 Memory Management | 7 Memory Management |
| 8 ***************** | 8 ***************** |
| 9 | 9 |
| 10 .. sectionauthor:: Vladimir Marangozov <Vladimir.Marangozov@inrialpes.fr> | 10 .. sectionauthor:: Vladimir Marangozov <Vladimir.Marangozov@inrialpes.fr> |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 Same as :cfunc:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of | 130 Same as :cfunc:`PyMem_Malloc`, but allocates ``(n * sizeof(TYPE))`` bytes of |
| 131 memory. Returns a pointer cast to :ctype:`TYPE\*`. The memory will not have | 131 memory. Returns a pointer cast to :ctype:`TYPE\*`. The memory will not have |
| 132 been initialized in any way. | 132 been initialized in any way. |
| 133 | 133 |
| 134 | 134 |
| 135 .. cfunction:: TYPE* PyMem_Resize(void *p, TYPE, size_t n) | 135 .. cfunction:: TYPE* PyMem_Resize(void *p, TYPE, size_t n) |
| 136 | 136 |
| 137 Same as :cfunc:`PyMem_Realloc`, but the memory block is resized to ``(n * | 137 Same as :cfunc:`PyMem_Realloc`, but the memory block is resized to ``(n * |
| 138 sizeof(TYPE))`` bytes. Returns a pointer cast to :ctype:`TYPE\*`. On return, | 138 sizeof(TYPE))`` bytes. Returns a pointer cast to :ctype:`TYPE\*`. On return, |
| 139 *p* will be a pointer to the new memory area, or *NULL* in the event of failu
re. | 139 *p* will be a pointer to the new memory area, or *NULL* in the event of |
| 140 failure. This is a C preprocessor macro; p is always reassigned. Save |
| 141 the original value of p to avoid losing memory when handling errors. |
| 140 | 142 |
| 141 | 143 |
| 142 .. cfunction:: void PyMem_Del(void *p) | 144 .. cfunction:: void PyMem_Del(void *p) |
| 143 | 145 |
| 144 Same as :cfunc:`PyMem_Free`. | 146 Same as :cfunc:`PyMem_Free`. |
| 145 | 147 |
| 146 In addition, the following macro sets are provided for calling the Python memory | 148 In addition, the following macro sets are provided for calling the Python memory |
| 147 allocator directly, without involving the C API functions listed above. However, | 149 allocator directly, without involving the C API functions listed above. However, |
| 148 note that their use does not preserve binary compatibility across Python | 150 note that their use does not preserve binary compatibility across Python |
| 149 versions and is therefore deprecated in extension modules. | 151 versions and is therefore deprecated in extension modules. |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 free(buf2); /* Right -- allocated via malloc() */ | 200 free(buf2); /* Right -- allocated via malloc() */ |
| 199 free(buf1); /* Fatal -- should be PyMem_Del() */ | 201 free(buf1); /* Fatal -- should be PyMem_Del() */ |
| 200 | 202 |
| 201 In addition to the functions aimed at handling raw memory blocks from the Python | 203 In addition to the functions aimed at handling raw memory blocks from the Python |
| 202 heap, objects in Python are allocated and released with :cfunc:`PyObject_New`, | 204 heap, objects in Python are allocated and released with :cfunc:`PyObject_New`, |
| 203 :cfunc:`PyObject_NewVar` and :cfunc:`PyObject_Del`. | 205 :cfunc:`PyObject_NewVar` and :cfunc:`PyObject_Del`. |
| 204 | 206 |
| 205 These will be explained in the next chapter on defining and implementing new | 207 These will be explained in the next chapter on defining and implementing new |
| 206 object types in C. | 208 object types in C. |
| 207 | 209 |
| OLD | NEW |