M
markww
Hi,
I want to use the vector container class to store pixel data. Currently
I have some memory allocated using c++'s new operator. I allocate the
memory differently based on if the pixel type is unsigned char or
unsigned short like this:
int nPixelType = ?; // unsigned short, or unsigned char?
BYTE *pByte = NULL;
switch (nPixelType) {
case UNSIGNED_SHORT:
pBtye = (BYTE *)new unsigned char[256 * 256];
break;
case UNSIGNED_CHAR:
pByte = (BYTE *)new unsigned char[256 * 256];
break;
}
Then I whenever I was doing image processing tasks, I would create a
temporary pointer to the data and cast it to the correct type:
unsigned short *p = (unsigned short *)pByte;
or
unsigned char *p = (unsigned char *)pByte;
Now it was suggested to me that I stop using raw pointers like this in
favor of vector containers. Can I translate the above into a vector of
BYTE and accomplish the same thing? Would it be possible to get around
having to cast the pointer before accessing it everytime?
vector<BYTE> vNew;
vNew.resize(256 * 256);
Thanks
I want to use the vector container class to store pixel data. Currently
I have some memory allocated using c++'s new operator. I allocate the
memory differently based on if the pixel type is unsigned char or
unsigned short like this:
int nPixelType = ?; // unsigned short, or unsigned char?
BYTE *pByte = NULL;
switch (nPixelType) {
case UNSIGNED_SHORT:
pBtye = (BYTE *)new unsigned char[256 * 256];
break;
case UNSIGNED_CHAR:
pByte = (BYTE *)new unsigned char[256 * 256];
break;
}
Then I whenever I was doing image processing tasks, I would create a
temporary pointer to the data and cast it to the correct type:
unsigned short *p = (unsigned short *)pByte;
or
unsigned char *p = (unsigned char *)pByte;
Now it was suggested to me that I stop using raw pointers like this in
favor of vector containers. Can I translate the above into a vector of
BYTE and accomplish the same thing? Would it be possible to get around
having to cast the pointer before accessing it everytime?
vector<BYTE> vNew;
vNew.resize(256 * 256);
Thanks