diff options
Diffstat (limited to 'docs/examples/tutorial/memory_allocation/some_memory.pyx')
-rw-r--r-- | docs/examples/tutorial/memory_allocation/some_memory.pyx | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/docs/examples/tutorial/memory_allocation/some_memory.pyx b/docs/examples/tutorial/memory_allocation/some_memory.pyx index fb272a88d..e6bb63b77 100644 --- a/docs/examples/tutorial/memory_allocation/some_memory.pyx +++ b/docs/examples/tutorial/memory_allocation/some_memory.pyx @@ -1,12 +1,13 @@ from cpython.mem cimport PyMem_Malloc, PyMem_Realloc, PyMem_Free -cdef class SomeMemory: +cdef class SomeMemory: cdef double* data def __cinit__(self, size_t number): # allocate some memory (uninitialised, may contain arbitrary data) - self.data = <double*> PyMem_Malloc(number * sizeof(double)) + self.data = <double*> PyMem_Malloc( + number * sizeof(double)) if not self.data: raise MemoryError() @@ -14,7 +15,8 @@ cdef class SomeMemory: # Allocates new_number * sizeof(double) bytes, # preserving the current content and making a best-effort to # re-use the original data location. - mem = <double*> PyMem_Realloc(self.data, new_number * sizeof(double)) + mem = <double*> PyMem_Realloc( + self.data, new_number * sizeof(double)) if not mem: raise MemoryError() # Only overwrite the pointer if the memory was really reallocated. |