Commit f01863d4 authored by Stefan Behnel's avatar Stefan Behnel

improve memory management example and comments

parent 08267b88
...@@ -85,15 +85,15 @@ e.g.:: ...@@ -85,15 +85,15 @@ e.g.::
cdef double* data cdef double* data
def __cinit__(self, number): def __cinit__(self, size_t number):
# allocate some memory (filled with random data) # 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: if not self.data:
raise MemoryError() raise MemoryError()
def resize(self, new_number): def resize(self, size_t new_number):
# Allocates new_number * sizeof(double) bytes, # Allocates new_number * sizeof(double) bytes,
# preserving the contents and making a best-effort to # preserving the current content and making a best-effort to
# re-use the original data location. # 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: if not mem:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment