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

Implimented GetSize for Arc<str>, tokio sync and fixed size of the &str #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

EnvOut
Copy link

@EnvOut EnvOut commented Feb 9, 2024

No description provided.

@EnvOut EnvOut force-pushed the Implimented-GetSize-for-Arc<str>,-tokio-sync-and-fixed-size-of-the-&str branch from 71daa7f to dbe6a0b Compare February 13, 2024 10:59
@EnvOut EnvOut force-pushed the Implimented-GetSize-for-Arc<str>,-tokio-sync-and-fixed-size-of-the-&str branch from dbe6a0b to e7d7519 Compare February 14, 2024 09:20
Comment on lines -143 to +146
impl GetSize for Duration {}
impl GetSize for SystemTime {}

impl GetSize for Duration {
fn get_stack_size() -> usize {
12
}
}
Copy link

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));
Copy link

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.

Comment on lines +339 to +341
fn get_size(&self) -> usize {
std::mem::size_of::<usize>() + (&**self).get_size()
}
Copy link

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

Suggested change
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()
}

Comment on lines +345 to +347
fn get_size(&self) -> usize {
std::mem::size_of::<usize>() + (&**self).get_size()
}
Copy link

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

Suggested change
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()
}

@bircni bircni mentioned this pull request Sep 9, 2024
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