Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
46d075e9
Commit
46d075e9
authored
Oct 12, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Plain Diff
merge 0.19.x branch into master
parents
f94ad597
39d9e0fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
docs/src/tutorial/memory_allocation.rst
docs/src/tutorial/memory_allocation.rst
+14
-10
No files found.
docs/src/tutorial/memory_allocation.rst
View file @
46d075e9
...
@@ -76,21 +76,25 @@ e.g.::
...
@@ -76,21 +76,25 @@ e.g.::
cdef double* data
cdef double* data
def __init__(self, number):
def __
c
init__(self, number):
# allocate some memory (filled with random data)
# allocate some memory (filled with random data)
self.data = <double*>
m
alloc(number * sizeof(double))
self.data = <double*>
PyMem_M
alloc(number * sizeof(double))
if
self.data == NULL
:
if
not self.data
:
raise MemoryError()
raise MemoryError()
def resize(self, new_number):
def resize(self, 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 contents and making a best-effort to
# re-use the original data location.
# re-use the original data location.
self.data = <double*> 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.
# On error (mem is NULL), the originally memory has not been freed.
self.data = mem
def __dealloc__(self, number):
def __dealloc__(self, number):
if self.data != NULL:
PyMem_Free(self.data) # no-op if self.data is NULL
free(self.data)
It should be noted that Cython has special support for (multi-dimensional)
It should be noted that Cython has special support for (multi-dimensional)
arrays of simple types via NumPy and memory views which are more full featured
arrays of simple types via NumPy and memory views which are more full featured
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment