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

Run analysis for size and alignment of non-primitive types #242

Open
Mec-iS opened this issue Nov 16, 2022 · 1 comment
Open

Run analysis for size and alignment of non-primitive types #242

Mec-iS opened this issue Nov 16, 2022 · 1 comment
Labels
explorative not an actual issue. Just a thing to look into
Milestone

Comments

@Mec-iS
Copy link
Collaborator

Mec-iS commented Nov 16, 2022

Run a check using std::mem to check for example:

trait Position {}

struct Coordinates(f64, f64);

impl Position for Coordinates {}

fn main() {
    let val = Coordinates(1.0, 2.0);
    let ref_: &Coordinates = &val;
    let pos_ref: &Position = &val as &Position;
    let ptr:       *const Coordinates = &val as *const Coordinates;
    let pos_ptr: *const Position  = &val as *const Position;
    
    println!("ref_: {}", std::mem::size_of_val(&ref_));
    println!("ptr: {}", std::mem::size_of_val(&ptr));
    println!("val: {}", std::mem::size_of_val(&val));
    println!("pos_ref: {}", std::mem::size_of_val(&pos_ref));
    println!("pos_ptr: {}", std::mem::size_of_val(&pos_ptr));
}

size of value and position in memory. About alignment see here.
On the side, is there a way we can use const fn somewhere if the custom traits to have it computed at compile-time?

@Mec-iS Mec-iS added the explorative not an actual issue. Just a thing to look into label Nov 16, 2022
@Mec-iS Mec-iS added this to the v0.5 milestone Nov 16, 2022
@Mec-iS
Copy link
Collaborator Author

Mec-iS commented Feb 15, 2023

Also run analysis using https://github.com/matt-kimball/allocscope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explorative not an actual issue. Just a thing to look into
Projects
None yet
Development

No branches or pull requests

1 participant