-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Add goodAllocationSize to GCAllocator #3962
Conversation
behavior for this.
| import core.bitop: bsr; | ||
|
|
||
| auto largestBit = bsr(n); | ||
| if (largestBit < 4) // less than 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably return before the bsr here.
|
Updated for better bsr usage. |
|
This probably doesn't jive well with the fact that the GC is pluggable at link-time, but apart from that I guess it looks good to me. |
|
Well, it may be inaccurate. It wouldn't be catastrophic. |
|
I think it's fine. Maybe when this is merged we can add a comment to gc.d informing the programmer of the assumptions made in std.allocator, so the issue can be dealt with when relevant. |
|
The GC bins are wasting quite some space (so should the should be replaced) and it's fairly ugly to hardcode them here. |
|
@MartinNowak GCAllocator reports basically that you will waste no space by allocating any size (it just rounds up to the next multiple of 16). I don't see the point of having this be incorrect, as there is no way to query an allocator for the actual memory size you just created. This is not a confirmation of the implementation of the GC, it's just trying to have GCAllocator accurately report the current situation. If you think the implementation should be done in a different way, then we can fix it when it makes sense. At this point, I don't see a lot of reason to add functions to the GC to satisfy something in std.experimental. |
| assert(GCAllocator.instance.goodAllocSize(s) == s); | ||
| assert(GCAllocator.instance.goodAllocSize(s - (s / 2) + 1) == s); | ||
|
|
||
| auto buffer = GCAllocator.instance.allocate(s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be better to request s - (s / 2) + 1 here instead of s? That way you do make sure that the allocator gets you the extra bytes up to s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can probably do both :) Not that hard to add a couple lines.
One thing I was concerned about actually, is having the GC insert extra metadata (such as array used size) that would bump the size up to the next bin.
|
Yah, I agree with @MartinNowak's point but am not worried about changes. I've never heard of plugging the GC during link time, and the moment we replace the strategy in the GC, the Phobos unittests will fail prompting change. |
|
Added additional unit test |
|
Nice, thanks! Let's hope it clears the unittest :o). |
|
Auto-merge toggled on |
Add goodAllocationSize to GCAllocator
GC always allocates from bins, and has very well-defined behavior here. So goodAllocSize can be implemented quite easily.
Rules:
I had to change some other unit tests because of the assumptions made for the default implementation of
IAllocator.goodAllocSize