Given your code:
BYTE *res; res = (BYTE *)realloc(res, (byte_len(res)+2));
res is a pointer to a BYTE type. The fact that it points to a continuous sequence of n BYTES is due to the fact that you did it. Length information is not part of the index. In other words, res points to only one BYTE , and if you point it to the right place that you have access to, you can use it to get BYTE values ββbefore or after it.
BYTE data[10]; BYTE *res = data[2];
So, to answer your question: you definitely know how much BYTE you allocated when you called malloc() or realloc() so that you keep track of the number.
Finally, using realloc() is incorrect, because if realloc() fails, you will skip memory. The standard way to use realloc() is to use a temporary:
BYTE *tmp; tmp = (BYTE *)realloc(res, n*2); if (tmp == NULL) { } else { res = tmp; }
Alok singhal
source share