Skip to content
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

fix issue 16398 - experimental allocators, add aligned reallocation for Posix #5857

Merged
merged 3 commits into from Nov 13, 2017
Merged

fix issue 16398 - experimental allocators, add aligned reallocation for Posix #5857

merged 3 commits into from Nov 13, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 13, 2017

The rationale for adding the primitive is that, like explained on bugzilla, the Windows version made for the Digital Mars standard C library already included a "pseudo" alignedReallocate that actually just allocates a new block, copies the old one and frees it.

@ghost ghost requested review from andralex, wilzbach and PetarKirov as code owners November 13, 2017 00:07
@dlang-bot
Copy link
Contributor

Thanks for your pull request, @bbasile! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.

Some tips to help speed things up:

  • smaller, focused PRs are easier to review than big ones

  • try not to mix up refactoring or style changes with bug fixes or feature enhancements

  • provide helpful commit messages explaining the rationale behind each change

Bear in mind that large or tricky changes may require multiple rounds of review and revision.

Please see CONTRIBUTING.md for more information.

Bugzilla references

Auto-close Bugzilla Description
16398 experimental allocators, add aligned reallocation for Posix

@ghost ghost changed the title fix issue 16398 - experimental allocators, add aligned reallocation f… fix issue 16398 - experimental allocators, add aligned reallocation for Posix Nov 13, 2017
auto p = alignedAllocate(s, a);
if (!p.ptr)
{
deallocate(b);
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to deallocate the original memory here - just signal failure and let the client decide.

}
else
{
if (b.ptr)
Copy link
Member

Choose a reason for hiding this comment

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

no need for this test - it works itself out

{
import std.algorithm.comparison : min;
const upTo = min(s, b.length);
p[0..upTo] = b[0..upTo];
Copy link
Member

Choose a reason for hiding this comment

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

space around ..

@@ -68,16 +68,14 @@ struct Mallocator
}

///
@nogc nothrow
@system unittest
@nogc @system nothrow unittest
{
auto buffer = Mallocator.instance.allocate(1024 * 1024 * 4);
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why these lines appear green? Is it because they weren't covered and now they are?

Copy link
Author

Choose a reason for hiding this comment

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

I have not the CodeCov plugin enabled and i see it green too, so it's the standard diff color.

On Posix, uses $(D alignedAllocate) and copies data around because there is
no realloc for aligned memory. On Windows, calls
$(HTTP msdn.microsoft.com/en-US/library/y69db7sx(v=vs.80).aspx,
On Posix this function is a helper that allocates and copies data around
Copy link
Member

Choose a reason for hiding this comment

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

The previous Posix-related explanation was more informative, even though it was incorrect :o).

no realloc for aligned memory. On Windows, calls
$(HTTP msdn.microsoft.com/en-US/library/y69db7sx(v=vs.80).aspx,
On Posix this function is a helper that allocates and copies data around
because there is no realloc for aligned memory.
Copy link
Member

Choose a reason for hiding this comment

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

please put "realloc" in backquotes

$(HTTP msdn.microsoft.com/en-US/library/y69db7sx(v=vs.80).aspx,
On Posix this function is a helper that allocates and copies data around
because there is no realloc for aligned memory.
On Windows, calls $(HTTP msdn.microsoft.com/en-US/library/y69db7sx(v=vs.80).aspx,
Copy link
Member

Choose a reason for hiding this comment

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

Use HTTPS so we're with the cool kids. Also the link has changed, now it's https://msdn.microsoft.com/en-us/library/y69db7sx.aspx

You may want to even try something like $(LUCKY __aligned_realloc site:microsoft.com, text text text)

On Posix, uses $(D alignedAllocate) and copies data around because there is
no realloc for aligned memory. On Windows, calls
$(HTTP msdn.microsoft.com/en-US/library/y69db7sx(v=vs.80).aspx,
On Posix this function is non system call that allocates and copies old data
Copy link
Member

Choose a reason for hiding this comment

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

"this function is non system call" does not parse, I'll fix the text myself

{
return false;
}
else
Copy link
Member

Choose a reason for hiding this comment

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

drop

@ghost
Copy link
Author

ghost commented Nov 13, 2017

hmmm what did you do Andrei ? It was green.

@andralex
Copy link
Member

there was a whitespace

@ghost
Copy link
Author

ghost commented Nov 13, 2017

thanks, green again.

@andralex andralex merged commit 0308bd6 into dlang:master Nov 13, 2017
@ghost ghost deleted the issue-16398 branch November 14, 2017 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants