You can't compute the length of an arbitary chunk of memory unless it's explicitly given be the nature of the datastructure or the os/memory manager has that functionality

If it's a nullterminated array of byte, then you simply forget to dereference before checking if it's nil(0). eg:

[pascal]
function getPtrLength(_ptr : PBYTE) : integer;
begin
Result := 0;
while ( _ptr^ <> 0 ) do
begin
inc(Result);
inc(_ptr);
end;
end;
[/pascal].

And as Andreaz is saying, you don't have any data structure in your array in your example