Skip to content

Avoid using the GC (when active) in toCStringThen#9483

Closed
jacob-carlborg wants to merge 1 commit intodlang:masterfrom
jacob-carlborg:toCStringThen-pure
Closed

Avoid using the GC (when active) in toCStringThen#9483
jacob-carlborg wants to merge 1 commit intodlang:masterfrom
jacob-carlborg:toCStringThen-pure

Conversation

@jacob-carlborg
Copy link
Contributor

By default xmalloc forwards to malloc. When using DMD as a library the GC is active and xmalloc forwards to the GC. Since the memory is always freed on return there's no reason to use the GC.

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#9483"

By default `xmalloc` forwards to `malloc`. When using DMD as a
library the GC is active and `xmalloc` forwards to the GC. Since the
memory is always freed on return there's no reason to use the GC.
@rainers
Copy link
Member

rainers commented Mar 24, 2019

On Windows, GC.malloc/free is usually faster than C's malloc, so this would not really be an improvement. (Recent tests when using a disabled GC in dmd showed slightly better performance than the non-GC version at the cost of using a bit more memory).

Returns:
The return value of `T`
*/
auto toCStringThen(alias dg)(const(char)[] src) nothrow
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove nothrow?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that it should be inferred, and maybe @jacob-carlborg has a non-nothrow delegate.

However we don't have any place in DMD that use exceptions, and IIRC Walter is clearly against it, which is why this is here in the first place.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the only reason I could see to remove it is if it were exposed in dmd as a library.

@jacob-carlborg
Copy link
Contributor Author

Ok, this seems pointless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments