-
-
Notifications
You must be signed in to change notification settings - Fork 702
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
chore(allocator): make and makeArray should allocate aligned memory #8577
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Luís Ferreira <[email protected]>
Thanks for your pull request, @ljmf00! Bugzilla referencesYour 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 locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#8577" |
Humm, why does RCIAllocator skip zeroed allocation method, but not aligned allocation, that is also optional? I think this is still badly designed, unfortunately. A generic allocator may only assume methods that are required to be implemented on every allocator, otherwise we rely on special return values that are both used for errors on allocation and not implemented. |
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.
Do we really need this? If make
/makeArray
is instantiated with AlignedMallocator
then all of this becomes moot.
I get the impression that make
/makeArray
is supposed to simply use the allocate method of the allocator that is being passed to it.
Yes, to improve correctness. I would expect correct alignment when providing |
Does that not happen now? |
No. That's what this PR is trying to solve, although, the design of the allocators doesn't allow doing it efficiently. It requires checking for See: struct S
{
align(512):
int a;
float b;
int c;
}
S* s1 = new S();
assert(cast(size_t)s1 % 512 == 0, "Misaligned"); // fine
S* s2 = AlignedMallocator.instance.make!S();
assert(cast(size_t)s2 % 512 == 0, "Misaligned"); // triggers |
@ljmf00 This seems to be a problem of |
Why are you required to create new allocators for each alignment sizes? I'm not getting your suggestion. Maybe you can ellaborate, but from my understanding that is not the intended way. There's a defined optional function that an allocator can define called The alignment property you mentioned is to describe the alignment of memory allocated with The fact that the generic allocator wrapper, provides a IMO, a generic allocator should only provide strictly mandatory functions to be implemented by any allocator. With the current behavior, no one is going to use |
Signed-off-by: Luís Ferreira [email protected]