Quote Originally Posted by User137
[pascal]
// expected result is 100 !! but its is
[/pascal]
However ptr^ := Random(100); can also place 0 within the array which would terminate length function early. Unless you manage data so there is no null inside it is more "proper" to store the length within a separate variable or possibly at the beginning of array.
good point i didnt look at that but either way, you can just add a 1 to the random(100), and when you grab the value from the ptr you just -1, however, if the length is going to be below 255 bytes, just use the first byte to record the length of the data when it is written.

obviously you can also do larger by allocating upto 4 bytes... or even 8 bytes to record datalen

also TMemoryStream is a class, which will most likely be slower, classes are created on the heap (which is slower btw). also he asked how to check manually, using a memory stream would be cheating.

anyways the problem you will have (if you were do check without knowing the size from a header or via api), many files can contain terminators... lol (null chars), exe files for example.

-Colin