-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a MemoryAllocator object for easier Cython memory management #18868
Comments
New commits:
|
Commit: |
Branch: public/18868 |
comment:2
This
should be in the |
comment:3
For performance, replace
by
|
comment:4
Can you please support all memory-allocation functions, like
by
(*) the multiplication can overflow. |
comment:5
Also for performance: keep |
comment:6
I guess that And I don't understand why you use
instead of
|
comment:7
[1] recommends |
comment:8
More about performance: note that your use of To solve some of these problems, I propose the following: add a small fixed array
in the
such that you avoid any allocations for |
comment:9
Replying to @dimpase:
In Sage, you should use absolutely use |
comment:10
More for performance: replace
by
|
comment:11
One more detail: replace
by
(and adjust the loop index in |
comment:15
Done
Makes no difference in any of the functions I touched, so I did not do it. Less
I added support for calloc. I do not need realloc (you can add a commit if you About realloc:
+1
Add a commit if you like. My problem with 'allocarray' is that it is Sage's
Done
Personally, for a simple reason: I trust C functions. Officially, it is for the
This is not a problem for the codes I touched, for malloc is never a dominant
Done.
Done. Jeroen, could you send reviews as one big comment rather than adding one every
Thaaaaaaaaanks, Nathann |
comment:16
Replying to @dimpase:
What is [1]? |
comment:17
Replying to @nathanncohen:
It actually comes from BSD, where it was added for security reasons (like I said, the multiplication in |
comment:18
Replying to @nathanncohen:
I thought that speed was an important reason to invent this new class. If you don't care so much about speed, there are several already-existing alternatives, such as Cython arrays. If speed is not so much a concern, then why are you reinventing the wheel? |
comment:29
Replying to @nathanncohen:
sure, why not; also, how about asking them about comment 23 ? |
Branch pushed to git repo; I updated commit sha1. New commits:
|
Branch pushed to git repo; I updated commit sha1. New commits:
|
Changed author from Nathann Cohen to Nathann Cohen, Jeroen Demeyer |
Reviewer: Jeroen Demeyer |
comment:32
This is ok for me, but someone needs to review my changes. |
comment:33
still, how about Apart from performance, there could be advantages in sense of debugging, as one can |
comment:34
Replying to @dimpase:
In any case, that's independent of this ticket. Second, |
comment:35
Third, Python's memory allocator does not support And if you're speaking about performance, recall that |
comment:36
Can somebody review this please? |
Changed reviewer from Jeroen Demeyer to Jeroen Demeyer, Volker Braun |
comment:39
Your were faster than me. |
Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. Last 10 new commits:
|
Dependencies: #18864 |
comment:43
Conflict with #18868 |
Changed branch from public/18868 to |
This is a re-implementation of an example appearing in Cython's documentation (see bottom of [1]).
The idea is simple: an object has a
.malloc
method, and returns arrays of memory. When that object is garbage-collected, the memory it allocated is automatically freed.This makes it much easier to deal with C pointers in Cython code, which must be freed before any 'return' and whenever an exception can be raised.
As an illustration of how useful this can be, I removed a lot of graph code.
Nathann
[1] http://docs.cython.org/src/tutorial/memory_allocation.html
Depends on #18864
CC: @dimpase @sagetrac-borassi @dcoudert @vbraun @jdemeyer @simon-king-jena
Component: cython
Author: Nathann Cohen, Jeroen Demeyer
Branch/Commit:
0304d9f
Reviewer: Jeroen Demeyer, Volker Braun
Issue created by migration from https://trac.sagemath.org/ticket/18868
The text was updated successfully, but these errors were encountered: