How to make data ownership explicit in C++ -


While working with references in Pointer and C ++, sometimes it is difficult to see that the indicator is on the referenced data Is ownership, or if it is just a temporary reference for example:

  example * i = new instance (); Example: Jammu = i;  

How can it be clarified that for example, who has 2 pointer ownership? In other words, how to clarify which pointers should be removed?

Note: In the above example it is not difficult to see, because it is a very small piece of code. However, when the pointer is duplicated and much is exceeded, it can be unclear.

You can not determine the owner, since there is no mechanism designed to know that the pointer What kind of memory is monitored?

If you are really worried about this, you can always start your naming convention, eg. In some of your variable names, through pre-post-fix, in other words, this is your code design that can give you this information. Since you (and your colleague) are writing the code, you can always ensure that this design has been implemented during implementation. Definitely this means that everyone has to follow these rules.

This is one of the reasons that the Common Coding Conference is very important so you can read your own and other public code and understand it.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -