The question is really what is in the //do Stuff
for( int i = 0; i < lines; i++ ) {
std::unique_ptr<BYTE[]> pLine( new BYTE[lineSize] );
//Do stuff
}
I would assume you are allocating the memory inside the loop to unique_ptr
because somewhere in the //Do stuff
section you are passing ownership of that memory to another object.
This if you try and do this:
std::unique_ptr<BYTE[]> pLine( new BYTE[lineSize] );
for( int i = 0; i < lines; i++ ) {
//Do stuff
}
The first time around the loop ownership is transfered and now pLine
contains a NULL pointer for the second a subsequent iteration.
If you are not transfering ownership then you are probably using the completely wrong method for memory management and a vector is probably a better idea.
for( int i = 0; i < lines; i++ ) {
std::vector<BYTE> pLine(lineSize);
//Do stuff
}
The advantage of putting it inside the loop it is re-initialized so all members are zero on every iteration of the loop. If the //Do Stuff
is affected by the state of the pLine
then it may be incorrect to move it outside the loop (without also doing some more work to make sure the state of pLine
is correct after each iteration.