-
Notifications
You must be signed in to change notification settings - Fork 11
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
Implimented GetSize for Arc<str>, tokio sync and fixed size of the &str #17
base: main
Are you sure you want to change the base?
Implimented GetSize for Arc<str>, tokio sync and fixed size of the &str #17
Conversation
71daa7f
to
dbe6a0b
Compare
dbe6a0b
to
e7d7519
Compare
impl GetSize for Duration {} | ||
impl GetSize for SystemTime {} | ||
|
||
impl GetSize for Duration { | ||
fn get_stack_size() -> usize { | ||
12 | ||
} | ||
} |
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.
question: Why make this change for Duration
?
It seems like the default implementation based on size_of
should be correct.
fn test_arc_str_size(){ | ||
let str_text = "a"; | ||
let arc: Arc<str> = Arc::from(str_text); | ||
assert_eq!(arc.get_size(), std::mem::size_of::<usize>() + std::mem::size_of_val(str_text)); |
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.
suggestion: This is incorrect.
The total size should include the stack size of the Arc
itself. In total it needs to store the 1 byte for the "a" plus the count (a usize) plus the fat pointer, which would be another two usizes worth of space.
fn get_size(&self) -> usize { | ||
std::mem::size_of::<usize>() + (&**self).get_size() | ||
} |
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.
suggestion: Shouldn't this be get_heap_size
?
I think your
fn get_size(&self) -> usize { | |
std::mem::size_of::<usize>() + (&**self).get_size() | |
} | |
fn get_heap_size(&self) -> usize { | |
std::mem::size_of::<usize>() + (&**self).get_size() | |
} |
fn get_size(&self) -> usize { | ||
std::mem::size_of::<usize>() + (&**self).get_size() | ||
} |
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.
suggestion: As above, this should be get_heap_size
fn get_size(&self) -> usize { | |
std::mem::size_of::<usize>() + (&**self).get_size() | |
} | |
fn get_heap_size(&self) -> usize { | |
std::mem::size_of::<usize>() + (&**self).get_size() | |
} |
No description provided.