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

Add implementation-details segment #2392

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

djmitche
Copy link
Collaborator

@djmitche djmitche commented Oct 1, 2024

This is a work-in-progress. I will probably need some help with some of these!

@djmitche djmitche linked an issue Oct 1, 2024 that may be closed by this pull request
@djmitche
Copy link
Collaborator Author

djmitche commented Oct 1, 2024

I think "dynamic array layout" refers to the differences in how C++ and Rust handle empty slices?

The other item in #2384 is "Return Value Optimization". What else should we include here?

@djmitche
Copy link
Collaborator Author

djmitche commented Oct 9, 2024

@fw-immunant @errge @anforowicz -- I've implemented a derivative of the linked list that started #1820 as an exercise, but I'm not sure I like it.

For one thing, I was surprised to find that even with T=u64, the List enum still takes 16 bytes (8 for T, 8 for the box, with the NULL value of the box used to signify List::Nil). That's a little disappointing.

Also, this exercise ends up getting into the question of whether the head node is stored on the stack. With the List enum (top of the exercise), it is, while with the List struct ("solution"), it is not. The result is that the two arguably use the same space, and differ only in where they allocate a little bit of it.

I'm curious for your thoughts, or if you have any better ideas for an exercise related to the niche optimization. I have also added a slide on empty containers and std::ptr::NonNull::dangle(), but this segment comes before the unsafe segment so I don't think it's OK to ask students to wor with dangle().

I'd also be open to other slides to add to this segment, especially if they lead naturally to an exercise.

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.

Add an "Implementation Details" segment
1 participant