-
Notifications
You must be signed in to change notification settings - Fork 106
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
support allocator api #426
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
54f977b
to
b43efc5
Compare
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
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.
So I am wondering if we should add a test to give basic coverage of this API in the snmalloc repo, so we detect breaks before it reaches snmalloc-rs?
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
d4a906f
to
b701d1c
Compare
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
it there a way to trigger the build again? |
So on
I have a Re-runall checks: I'll hit it for you. Do you need some help with the Windows tests? |
Ha, I guess sth interesting is happening on Win. I will have a look later when I can clear some space for MSVC on my PC ;). |
Running your test gives:
failing on
in |
Signed-off-by: SchrodingerZhu <i@zhuyi.fan>
|
||
void test_allocator_vector() | ||
{ | ||
using Inner = std::vector<size_t, RAllocator<size_t>>; |
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.
Could you add some comments to this test explaining what it is testing?
{ | ||
return ThreadAlloc::get().alloc(aligned_size(alignment, size)); | ||
} | ||
enum class SizeChange |
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.
Please can you add a comment explaining (and, ideally, linking to) the Rust APIs that this is intended to expose?
if ( | ||
size_to_sizeclass_full(aligned_old_size).raw() == | ||
size_to_sizeclass_full(aligned_new_size).raw()) | ||
return ptr; |
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.
return ptr; | |
{ | |
return ptr; | |
} |
As a general style point we should have braces around all if
statement bodies because it reduces bugs introduced when someone edits the code later, but this case is a particularly good example of needing them for readability because the wrapped line in the condition is at the same indent level as the body of the conditiona.
size_to_sizeclass_full(aligned_new_size).raw()) | ||
return ptr; | ||
// this may memset more than it needs, but doing so increases | ||
// the possibility for large area to be efficiently zeroed by special |
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.
Those methods are exposed in the PAL, they could be called here.
Sure! I am still sorting out the design. |
@mjp41 @davidchisnall I begin to wonder whether we should only expose sth like I wanted to support sth like: fn allocator_supports_vector() {
let allocator = SnAllocator::new();
let mut vec = std::vec::Vec::new_in(&allocator);
let mut sum: usize = 0;
for i in 1..512usize {
vec.push(i);
sum += i * i;
}
let res = vec.into_iter().flat_map(|x| {
let mut v = std::vec::Vec::new_in(&allocator);
for _ in 0..x {
v.push(x);
}
v
}).sum();
assert_eq!(sum, res);
} But I begin to wonder whether it is a bad decision to let user use a |
export FFIs to enable snmalloc being used as a separate allocator
https://doc.rust-lang.org/stable/std/alloc/trait.Allocator.html