-
-
Notifications
You must be signed in to change notification settings - Fork 415
Use malloc and free instead of GC allocating inside (w)string.sort #746
Conversation
Still pure? void main() pure
{
wchar[] s;
s.sort;
} |
It's not called directly, so no change there. The attributes are explicitly set when the compiler magics the definition. |
would be nice if the |
Use malloc and free instead of GC allocating inside (w)string.sort
I guess I go into C-mode when I start calling malloc. |
@yebblies |
|
HA! |
That's right, sadly, this PR in its current form is broken because decode() can throw. This can be fixed, however. |
Has anyone ever timed malloc/free against GC.malloc/GC.free? Anyhow please fix. |
I recently did during the scopebuffer discussion. Quoting from there (is there a way to link to a comment?): "I've made a few measurements comparing the stdlib version with the GC using the example provided by blackwhale, with an argument of 250, which causes one allocation and one reallocation per iteration. On Win32, the GC version takes only 75% of the time of the stdlib version! There are some easy optimizations to the GC version which could make it par on Win64 aswell (removing the GC proxy, making the GC implementation nothrow, disabling setting memory to zero in malloc. etc). Maybe someone can make a similar measurement for linux..." In a situation like in this PR, using GC.malloc/free is better, because you don't pay for additional exception handling. If something throws you just get garbage to be collected later. |
This pull was not about speed, it was about removing a hidden GC allocation and possible collection trigger. There is no reason sorting arrays of chars needs a GC present at all. |
I just asked this as a general question. It might not always be a good idea to replace GC.malloc. |
@rainers Yes, just click on the time of the comment, and there will be a link. E.g. |
I understand. Maybe we should have an alias for symbols to use for temporary allocations.
Thanks. I was trying the name and the avatar, but somehow missed the time. |
Did anyone fix the potential memory leak yet? |
No description provided.