-
Notifications
You must be signed in to change notification settings - Fork 9
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
Must the returned sizes of Allocator
methods fit in Layout
?
#107
Comments
( Is it reasonable to require the reported allocation size to be a multiple of the requested alignment? I don't see any potential reason to overallocate which isn't to a multiple of alignment other than to cause problems. This also has the benefit of the caller being able to use I suppose the use case is when making a request for a layout which is not padded to alignment itself, e.g. a small type aligned to a page. Interestingly enough, though, the behavior that a caller would want (where returned size is not a multiple of align) is actually to round down to alignment, as the rounded up value isn't really usable for nearly anything, as it can't be used to check access for being inbounds nor even to deallocate the pointer. I think this is a reasonable requirement. In practice, allocations which would fail this test are pretty degenerate anyway, as they take up a quarter of the address space at absolute minimum. |
From latest
So statement above is no longer valid (I guess they were successful in their effort). There may be reason to overallocate with size not a multiple of alignment. Reason for overallocating in general applies - to not keep too small free blocks. For convenience we may add a method to construct |
(Discussion on Zulip)
The documentation of
Allocator::allocate
makes only the following guarantees in case of successful allocation:grow
andshrink
have similar guarantees.The preconditions of
Layout::from_size_align
contain the following:Does this imply that the allocation returned by
Allocator::allocate
may have a size that is less thanisize::MAX
but very close, such that rounding it up tolayout.align()
will lead to an overflow?In other words, assuming
allocate
doesn't panic, can the following function ever panic?The text was updated successfully, but these errors were encountered: