Skip to content

the book should mention the difference between vectors and arrays. #20948

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

Closed
bharadwaj6 opened this issue Jan 11, 2015 · 3 comments · Fixed by #22305
Closed

the book should mention the difference between vectors and arrays. #20948

bharadwaj6 opened this issue Jan 11, 2015 · 3 comments · Fixed by #22305

Comments

@bharadwaj6
Copy link

I have found out that vectors are heap allocated whereas arrays are stack allocated, but this was not mentioned anywhere in the book.

@kmcallister
Copy link
Contributor

Arrays are allocated directly within the containing structure. So Box<[u8; 3]> is heap allocated, but let x: [u8; 3] = ... is stack-allocated like any let variable.

@bharadwaj6
Copy link
Author

Let me summarize it here: So unless we box the array declaration, arrays would be allocated on the stack, whereas vectors would always be allocated on the heap (possibly because they are implemented as box types in vec!?). Correct me if I am wrong here.

@steveklabnik steveklabnik changed the title rustbook: should mention the difference between vectors and arrays. the book should mention the difference between vectors and arrays. Jan 11, 2015
@steveklabnik
Copy link
Member

Yes.

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 a pull request may close this issue.

3 participants