I
Immortal Nephi
I want to know if vector performance is faster than traditional char
performance through loop.
I can choose either method 1 or method 2 if both methods have fixed
size and data is in range of array length. I would prefer to use
method 2, but method 1 has short code lines than method 2 does.
Method 1:
const int size = 256;
vector< char > source, target;
for( int index = 0; index < size; index++ )
source.push_back( index );
target = source;
Method 2:
const int size = 256;
char *source = new char[ size ];
char *target = new char[ size ];
for( int index = 0; index < size; index++ )
source[ index ] = index;
for( int index = 0; index < size; index++ )
target[ index ] = source[ index ];
delete [] target;
delete [] source;
performance through loop.
I can choose either method 1 or method 2 if both methods have fixed
size and data is in range of array length. I would prefer to use
method 2, but method 1 has short code lines than method 2 does.
Method 1:
const int size = 256;
vector< char > source, target;
for( int index = 0; index < size; index++ )
source.push_back( index );
target = source;
Method 2:
const int size = 256;
char *source = new char[ size ];
char *target = new char[ size ];
for( int index = 0; index < size; index++ )
source[ index ] = index;
for( int index = 0; index < size; index++ )
target[ index ] = source[ index ];
delete [] target;
delete [] source;