Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Account.cpp] explicitly destroy priv->splits
better than 35b6fb7
- Loading branch information
better than 35b6fb7
871f669
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this better than shrink_to_fit? Also, I haven't found convincing evidence that calling this destructor explicitly is safe.
Just a gnucash user, who likes coding, and doesn't want his gnucash to crash one day :-)
871f669
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better because it runs the destructor which doesn't otherwise run instead of just freeing the space allocated for the vector's contents. Although we're not explicitly using placement new we're doing essentially the same thing. You'll see in the example that explicitly calling the object's destructor is required.
871f669
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! Just for my education, when you have a minute, can you show me how you're doing essentially the same thing as placement new? Thanks!
871f669
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
AccountPrivate
allocation andmemset
to 0 is buried in the GObject macros, which also arrange for callinggnc_account_init
whereinpriv->splits.clear()
is the first place where that offset is treated as a std::vector.If you want deeper understanding a good place to start is the GObject tutorial.