Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
rust
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
orestis.malaspin
rust
Commits
b606ad2b
There was a problem fetching the pipeline summary.
Commit
b606ad2b
authored
6 years ago
by
orestis.malaspin
Browse files
Options
Downloads
Patches
Plain Diff
updated ownership
parent
78929b2d
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
presentation/intro.md
+28
-1
28 additions, 1 deletion
presentation/intro.md
with
28 additions
and
1 deletion
presentation/intro.md
+
28
−
1
View file @
b606ad2b
...
...
@@ -152,10 +152,15 @@ fn main() {
notebook.push("Les oiseaux chantent.");
do_something(notebook); // ownership transféré à do_something
// do_something(notebook); // redo something
do_something(notebook); // ici notebook ne possède plus ses données
// => erreur de compilation!
}
</code></pre>
. . .
Le transfert de l'ownership est complètement décidé à la
**compilation**
.
## Ownership en pratique
Ce qui se passe en mémoire:
...
...
@@ -168,6 +173,28 @@ Ce qui se passe en mémoire:
**`notebook` est détruit à la fin de `do_something` et ne peut plus être réutilisé**
## Ownership en pratique
En C++ une sytaxe similaire a un effet complètement différent
```
void do_something(notebook: vector<string>) {
// Do something with the notebook
} // la variable locale notebook est détruite et ses données aussi
// le notebook du main existe toujours
void main() {
vector<string> notebook; // par défaut notebook est mutable
notebook.push_back("Il fait beau.");
notebook.push_back("Les oiseaux chantent.");
do_something(notebook); // le copy-constructeur de notebook
// est invoqué
do_something(notebook); // on peut réutiliser notebook sans problème
}
```
<!-- -
`vector`
et
`string`
sont alignés en mémoire.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment