Length of a BYTE array in C++ -


I have a program in C ++ that has a BYTE array that stores some value. I need to find the length of that array, that is, the number of bytes in that array Please help me in this regard.

This code is:

  BYTE * res; Res = (byte *) reel (race, (byte_ALEN +2));  

byte_len is a hypothetical task that gives length of BYTE array and I have to know how to implement it.

Looking at your code:

  BYTE * res; Res = (byte *) reel (race, (byte_ALEN +2));  

res is an indicator for typing BYTE . The fact is that this is due to a sequential sequence of n BYTES indicates that you have done that information about length is not a part of the indicator. In other words, res indicates only a byte , and if you point it to the right place, where you have access, you can use it for the BYTE values ​​before or after it

  BYTE data [10]; BYTE * res = data [2]; / * Now you can access res [7] * res [7] * /  

, to answer your question: You definitely know how many BYTE s When you are called malloc () or realloc () , then you should keep track of numbers.

Finally, your use of the code> Realloc () is incorrect, because if realloc () fails, then you leak the memory < The standard way to use Code> realloc () is to use temporary:

  BYTE * tmp; Tmp = (byte *) reel (race, n * 2); If (tmp == NULL) {/ * realloc is unsuccessful, the res is still valid * /} and {/ * you can no longer use res, but tmp is valid. Reassign * / res = tmp; }  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -