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

Make Volatile derive Copy. #6

Closed
wants to merge 1 commit into from

Conversation

cedws
Copy link

@cedws cedws commented Oct 26, 2018

Hi there. This PR makes the Volatile struct derive Copy. I'm not sure whether this will have any negative or unintended consequences.

To clarify what this is needed for, I am currently looking to improve some of the VGA text buffer code in Philipp Oppermann's blog_os. This PR allows an optimisation to be made for which I will send a PR there too.

@phil-opp
Copy link
Member

Hi, thanks for the PR! The problem with implementing Copy for Volatile is that it makes accidental copies possible. Most of the time, a volatile refers to a specific memory location, so it does not make much sense to copy it e.g. to the stack. See #5 (comment) for an example.

I hope that rust-lang/rust#53645 is merged soon. It implements const generics, which means that we could create a VolatileArray<T, const N> type, which could solve the initialization problem easily through a VolatileArray::new(array: [T; N]) method.

@cedws
Copy link
Author

cedws commented Oct 27, 2018

Ah I see, I was trying to do something similar with [Volatile::new(_); N];. It seems VolatileArray would be more optimal. Thanks a lot, I have a few other changes for the kernel that you might like.

@cedws cedws closed this Oct 27, 2018
@cedws cedws deleted the feature/DeriveCopy branch January 4, 2019 17:26
@videah videah mentioned this pull request Nov 8, 2019
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