How to get size of byte pointer?

abc abc 351 Reputation points
2021-02-16T11:01:25.94+00:00

How to get the size of byte*.
I have byte* mData; this byte pointer is memory allocated and filled by a dll.
In the main application how to get the length or size of data occupied by the byte pointer.

Developer technologies C++
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Guido Franzke 2,191 Reputation points
    2021-02-16T11:24:38.937+00:00

    Hello,
    this is impossible. The function in the dll that fills the pointer must return the size of the data (amount of byte entries). Check the documentation of the function.
    Regards, Guido
    Edit: if it was a 0-terminated char array (char*), then you could check with strlen. Check the documentation of the filling function if the byte array (your byte* mData) has such a special End-byte too.

    0 comments No comments

  2. Viorel 122.5K Reputation points
    2021-02-16T11:28:09.647+00:00

    I think that it is possible in case of malloc, calloc, realloc. For example:

    byte* mData = (byte*)malloc( 1000 );
    . . .
    size_t size = _msize( mData ); // result: 1000
    

    (This probably needs /MD or /MDd options).

    In case of HeapAlloc, you can use HeapSize.


  3. Sam of Simple Samples 5,546 Reputation points
    2021-02-17T20:10:44.143+00:00

    It is not clear whether you are asking about the size of the data pointed to or the size of the pointer itself. If you need the size of the pointer itself then use the sizeof operator.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.