-
Notifications
You must be signed in to change notification settings - Fork 384
Cascaded allocator #2113
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
base: master
Are you sure you want to change the base?
Cascaded allocator #2113
Changes from 4 commits
bd320b1
37dc8f4
c61b9be
6166f88
32d3d1f
e2a5511
6835890
150eb7b
089af45
ac87bd4
b71f82d
34abb6e
cf39680
78e7165
e5e55bc
00016bf
912d9db
833bc87
40675b0
148734d
6e9a17c
d065069
eba85a4
1e1862d
0f26ecb
4a7fcd0
cf686b3
4c27ab0
8210ac0
e8d9b51
63e543f
d4e7d14
874d9cb
92066a1
4a9c114
8450156
0c8067c
cc4053c
ac5f611
fec93be
42b409e
a837b5d
c9ead44
021ef62
92c3499
b84e0c4
58da8c3
818c631
76ceba9
c19e903
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,9 +190,16 @@ ACE_Cascaded_Dynamic_Cached_Allocator<ACE_LOCK>::ACE_Cascaded_Dynamic_Cached_All | |
// If ACE_NEW fails, the hierarchy_ will be reconstructed when malloc API is called. | ||
ACE_NEW (tmp, comb_alloc_type(this->initial_n_chunks_, this->chunk_size_)); | ||
|
||
// Increase the chunk sum if succeed. | ||
this->chunk_sum_ += tmp->pool_depth(); | ||
// Consider the exception of vector push_back call | ||
this->hierarchy_.push_back(tmp); | ||
if (0 == this->hierarchy_.size()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when push_back fails it will throw, maybe use std::unique_ptr? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These APIs have strong exception safety guarantee, so there is no need to use std::unique_ptr. Is it true ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, I can see the result of these calls to judge whether potential exceptions have occurred There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See https://en.cppreference.com/w/cpp/language/exceptions, push_back can throw, when it does the state of the std::vector is guaranteed at that moment, but it will not just return. The exception should go back to the caller to my idea, your allocator should not leak when push_back (or any operation it uses) throws There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when using unique_ptr the check after the push_back seems invalid There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have used std::unique_ptr for idiom in new commit But for a vector of pointer, I think sdt::vector can keep strong exception guarantee.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, Your idea is right! The APIs provide strong exception guarantee, but not Nothrow I will delete the defence codes |
||
{ | ||
delete tmp; | ||
return; | ||
} | ||
|
||
// Increase the chunk sum if all points having potential risk of exception is passed. | ||
this->chunk_sum_ += tmp->pool_depth (); | ||
} | ||
|
||
template <class ACE_LOCK> | ||
|
@@ -227,11 +234,21 @@ ACE_Cascaded_Dynamic_Cached_Allocator<ACE_LOCK>::malloc (size_t nbytes) | |
if(ptr == nullptr) | ||
{ | ||
comb_alloc_ptr tmp; | ||
ACE_NEW_RETURN (tmp, comb_alloc_type(this->initial_n_chunks_ * 2 * this->hierarchy_.size(), this->chunk_size_), nullptr); | ||
ACE_NEW_RETURN (tmp, comb_alloc_type(this->initial_n_chunks_ * (1 << this->hierarchy_.size()), | ||
this->chunk_size_), | ||
nullptr); | ||
|
||
// Increase the chunk sum if succeed. | ||
this->chunk_sum_ += tmp->pool_depth(); | ||
// Consider the exception of vector push_back call | ||
const auto old_size = this->hierarchy_.size(); | ||
this->hierarchy_.push_back(tmp); | ||
if (old_size == this->hierarchy_.size()) | ||
{ | ||
delete tmp; | ||
return nullptr; | ||
} | ||
|
||
// Increase the chunk sum if all points having potential risk of exception is passed. | ||
this->chunk_sum_ += tmp->pool_depth (); | ||
ptr = tmp->malloc(nbytes); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.