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

Expose malloc_usable_size in the high-level crate. #18

Merged
merged 1 commit into from
Oct 14, 2017

Conversation

SimonSapin
Copy link
Contributor

No description provided.

@SimonSapin
Copy link
Contributor Author

Or perhaps it is enough for users to depend on the jemallocator_sys crate directly? What do you think?

Copy link
Collaborator

@alexcrichton alexcrichton left a 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is : Sized needed here?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@alexcrichton alexcrichton merged commit 672dd78 into gnzlbg:master Oct 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants