Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Conversation

yebblies
Copy link
Contributor

No description provided.

@monarchdodra
Copy link
Contributor

Still pure?

void main() pure
{
    wchar[] s;
    s.sort;
}

@yebblies
Copy link
Contributor Author

It's not called directly, so no change there. The attributes are explicitly set when the compiler magics the definition.

@andralex
Copy link
Member

would be nice if the frees went as scope(exit) right after allocation

andralex added a commit that referenced this pull request Mar 20, 2014
Use malloc and free instead of GC allocating inside (w)string.sort
@andralex andralex merged commit a1d4550 into dlang:master Mar 20, 2014
@yebblies yebblies deleted the gcsort branch March 20, 2014 17:08
@yebblies
Copy link
Contributor Author

would be nice if the frees went as scope(exit) right after allocation

I guess I go into C-mode when I start calling malloc.

@andralex
Copy link
Member

@yebblies malloc + scope = bliss

@dnadlinger
Copy link
Contributor

decode throws, right? Does the current implementation contain a potential memory leak, then?

@andralex
Copy link
Member

HA!

@WalterBright
Copy link
Member

That's right, sadly, this PR in its current form is broken because decode() can throw. This can be fixed, however.

@MartinNowak
Copy link
Member

Has anyone ever timed malloc/free against GC.malloc/GC.free? Anyhow please fix.

@rainers
Copy link
Member

rainers commented Mar 24, 2014

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!
On Win64, the GC version needs about 9% longer than 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.

@yebblies
Copy link
Contributor Author

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.

@MartinNowak
Copy link
Member

I just asked this as a general question. It might not always be a good idea to replace GC.malloc.

@schveiguy
Copy link
Member

Quoting from there (is there a way to link to a comment?):

@rainers Yes, just click on the time of the comment, and there will be a link. E.g.
#739 (comment)

@rainers
Copy link
Member

rainers commented Mar 25, 2014

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 understand. Maybe we should have an alias for symbols to use for temporary allocations.

(is there a way to link to a comment?):

Yes, just click on the time of the comment, and there will be a link.

Thanks. I was trying the name and the avatar, but somehow missed the time.

@MartinNowak
Copy link
Member

Did anyone fix the potential memory leak yet?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants