Hi Pradeep,
along with the others, I recommend consulting a text book.
*However*, here are a few comments which may serve as a guide.
std::vector<uint_8*> (m_Data);
As others have mentioned, you probably mean to write
"std::vector<uint_8> m_Data". This creates a vector of uint_8's and
this vector is named m_Data. The asterisk (*) after the uint_8 causes
the compiler to create a vector containing the addresses of uint_8's.
As a result, when you do the copying at the end (i.e., "m_Data[6] =
&srcPtr[0]") you are just copying the addresses of various substrings
of srcPtr. I think you want the actual octets. In that case, drop the
* in the vector definition, and drop the & in front of your srcPtr's.
Also, your vector _is_ empty. When you create a std::vector it is
initially empty *using the default constructor*. Before you try to
assign values to this vector you need to
* resize() it, or
* state how large you want the vector to initially be in the
constructor, or
* push_back() the values onto the end of the vector.
See here:
http://www.cplusplus.com/reference/stl/vector/
uint8_t *srcPtr = new uint8_t[6];
memset(static_cast<uint8_t*>(srcPtr), 0,(sizeof(uint8_t)* 6));
if(srcPtr) { srcPtr= // A API returning const_uint* }
As noted above, the static_cast, and the "if(srcPtr)" are unnecessary.
The former because you are casting a pointer to the same type; this
literally does nothing. The second because C++ guarantees that srcPtr
exists at this point. Had "new" not worked, your program would have
terminated (it would have thrown an exception which, by default, would
cause your program to terminate since you aren't handling it. Don't
worry about that until you have the basics down, thouhgh...)
The assignment to srcPtr inside the "if" is troublesome. I'm assuming
that you think this copies the values of the const_uint* returned by
your API to the memory you just allocated. It doesn't. It copies the
pointer. Note that the pointer to the array you just allocated is now
lost. This will cause a memory leak 'cause you'll have no way to free
the 6 bytes you allocated by "new".
In fact, you're probably best not doing the "new" at all -- I don't
see the point of copying to the array pointed to by srcPtr, only to
copy it out right away to m_Data.
Probably all you need to write for those three lines is
const_uint* srcPtr = WhateverYourAPIIsCalled();
m_Data[6] = &srcPtr[0];
...
With the adjustments above, you could just loop over the copy:
for (unsigned i = 0; i < 6; ++i) m_Data[6 + i] = srcPtr
;
Finally, you probably don't need to use "new" for six bytes. I sense
that you wanted to use srcPtr only temporarily. In which case you
might as well allocate a measly six bytes on the stack, i.e., "uint_8
src[6]". Having to use "new" and then "delete[]" later just adds
complication for a small, local variable.
--Jonathan