-
Notifications
You must be signed in to change notification settings - Fork 118
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
Expose malloc_usable_size
in the high-level crate.
#18
Conversation
Or perhaps it is enough for users to depend on the |
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.
Nah seems fine to me to add, thanks!
src/lib.rs
Outdated
/// Any discrepancy between the requested allocation size | ||
/// and the size reported by this function should not be depended on, | ||
/// since such behavior is entirely implementation-dependent. | ||
pub unsafe fn usable_size<T: Sized>(ptr: *const T) -> usize { |
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.
Is : Sized
needed here?
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 guess it’s not in the sense that it’s the default, but ?Sized
would cause the cast to *const c_void
to not work… won’t it? Hmm, I just tried and it looks like an casting unsized raw pointer to sized is allowed, though documenting it is "TODO" in https://doc.rust-lang.org/nightly/nomicon/casts.html. I don’t know if it’s desirable here, though.
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.
Oh sorry I just mean that : Sized
is the default, so the choices here are basically : ?Sized
or no bounds at all, but I like the idea of using a sized pointer as jemalloc isn't the one allocating vtables.
/// rather it is provided solely as a tool for introspection purposes. | ||
/// Any discrepancy between the requested allocation size | ||
/// and the size reported by this function should not be depended on, | ||
/// since such behavior is entirely implementation-dependent. |
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.
Mind adding an # Unsafety
section here as well?
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.
Done, though I couldn’t find info on undefined behavior with this function in http://jemalloc.net/jemalloc.3.html so I based it on what I recall hearing about allocators in general.
6de2ff5
to
d24b998
Compare
No description provided.