Edit: I appreciate all the comments and it helped me to understand more about it. I spent the whole afternoon trying to understand that and you clarified everything. Thank you very much ;D
All variables should be initialised when defined. The default is nullptr for pointers. If possible, variables should be initialised with their required value when defined. So:
auto pField {newunsignedchar[FieldHeight * FieldWidget]};
> When should I use nullptr and why not declare a pointer?
> I'm learning C++
As far as possible, never; particularly when one is learning C++. Use std::vector<> instead.
This is so much better: std::vector<unsigned char> Field( FieldHeight * FieldWidth ) ;
As Sutter and Alexandrescu point out in 'C++ Coding Standards: 101 Rules, Guidelines, and Best Practices':
Use vector and string instead of arrays
Why juggle Ming vases? Avoid implementing array abstractions with C-style arrays, pointer arithmetic, and memory management primitives. Using vector or string not only makes your life easier, but also helps you write safer and more scalable software.
...
Here are some reasons to prefer the standard facilities over C-style arrays:
They manage their own memory automatically ...
They have a rich interface ...
They are compatible with C's memory model ...
They offer extended checking ...
They don't waste much efficiency for all that ...
They foster optimizations ...
For times when you don't know yet what the pointer will point to, and times when the pointer will change its value many times and sometimes won't be pointing at anything valid.
type name = dummy; // declaration and initialization of variable 'name'
name = value; // assignment to variable 'name'
Should we initialize a variable with known value when we declare it? Yes.
If you have variables with unknown values, you might forget that and use them anyway.
Can we always initialize with "real" value? No. Getting the real value might be delayed or conditional.
But you still need a value that you can show (with a test) to be "not real" but known. The "dummy".
As far as possible, avoid using dynamically allocated arrays with either raw pointers or managed pointers.
Dynamically allocated arrays are best represented by std::vector<>. They keep track of their current size; they help us avoid out-of-bound access errors (a range-based loop or a v.begin() v.end() loop is inherently bounds-safe). std::vector<> is actually smarter than the 'smart' pointer std::unique_ptr; using a smart pointer where std::vector<> is a better choice is not a particularly smart thing to do.
If you want to measure the size of your array and iterate your array at given some point, then vector offers lot of useful functionality but in pointer version you need to manage manually. There is also a performance cost involves in vector during instantization.
Below links describes performance data’s for vectors when it handling with integers types. This also help you some level to get some more insight.