Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Donald Haase
Cockatrice
Commits
0de0658a
Commit
0de0658a
authored
Aug 07, 2014
by
Gavin Bisesi
Browse files
Merge pull request #269 from arxanas/style-guide-memory-management
Added section on memory management to CONTRIBUTING.md.
parents
fe3dc025
bee1ff39
Changes
1
Hide whitespace changes
Inline
Side-by-side
CONTRIBUTING.md
View file @
0de0658a
...
...
@@ -103,3 +103,32 @@ Use only spaces. Four spaces per tab.
Do not have trailing whitespace in your lines.
Lines should be 80 characters or less, as a soft limit.
### Memory Management ###
New code should be written using references over pointers and stack allocation
over heap allocation wherever possible.
// Good: uses stack allocation and references
void showCard(const Card &card);
int main()
{
Card card;
showCard(card);
}
// Bad: relies on manual memory management and doesn't give us much
// null-safety.
void showCard(const Card *card);
int main()
{
Card *card = new Card;
showCard(card);
delete card;
}
(Remember to pass by
`const`
reference wherever possible, to avoid accidentally
mutating objects.)
When pointers can't be avoided, try to use a smart pointer of some sort, such
as
`QScopedPointer`
, or, less preferably,
`QSharedPointer`
.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment