This repository was archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize MemoryAllocator and add allocarray()
- Loading branch information
Showing
8 changed files
with
117 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
from sage.ext.memory cimport malloc, free, realloc, check_calloc, check_allocarray, check_realloc, check_reallocarray | ||
cimport cython | ||
|
||
@cython.final | ||
cdef class MemoryAllocator: | ||
cdef size_t n | ||
cdef size_t max_size | ||
cdef size_t size | ||
cdef void ** pointers | ||
cdef void * malloc(self, size_t size) except NULL | ||
cdef void * calloc(self, size_t nmemb, size_t size) except NULL | ||
cdef enlarge_if_needed(self) except -1 | ||
cdef void * static_pointers[16] # If n <= 16, store pointers here | ||
|
||
cdef void * malloc(self, size_t size) except? NULL | ||
cdef void * calloc(self, size_t nmemb, size_t size) except? NULL | ||
cdef void * allocarray(self, size_t nmemb, size_t size) except? NULL | ||
cdef int resize(self, size_t new_size) except -1 | ||
cdef inline int enlarge_if_needed(self) except -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters