I am trying to read the full binarystream into a memoryblock.
When the file size exceeds 2GB I get a zero sized memoryblock.
This happens with both 32 and 64 Bit builds.
Any help ?
Dim bstream As BinaryStream
Dim mb As MemoryBlock
MsgBox str(bstream.Length)
mb = bstream.Read(bstream.Length)
MsgBox str(mb.Size)
I don’t have an answer to your question, but am wondering why you do this. What do you do with the contents of the MemoryBlock? And can you do it in chunks instead?
I am actually trying to read in an entire pdf file so that I can access randomly any part of that file.
Theoretically the documentation says there is no practical limit for memoryblocks in a 64 bit build.
But the problem exists in both 32 and 64 bit builds.
Which is the best way to solve this problem ?
#Pragma BackgroundTasks False
Var blockSize As Integer = 1024 * 1024 * 128
Var Offset As Integer
Var s As String
Var readFile As FolderItem = FolderItem.ShowOpenFileDialog("")
If readFile <> Nil And readFile.Exists Then
Var ReadStream As TextInputStream = TextInputStream.Open(readFile)
Var mb As MemoryBlock = New MemoryBlock(readFile.Length)
Do Until ReadStream.EOF
s = ReadStream.Read(blockSize)
mb.StringValue(Offset, s.Bytes) = s
Offset = Offset + s.Bytes
Loop
readStream.Close
End If
Btw. The LR is OK, there is no practical limit in 64Bit-Apps, but Strings are limited to 2GB.
Var mb As MemoryBlock = New MemoryBlock(readFile.Length)
In the above statement, if readFile.Length exceeds 2GB then the size of the memoryblock mb becomes negative. This happens with the 64 Bit build. In the 32 Bit build, it gives an out of memory error.
When the file size is 2203001756 bytes, the size of the memoryblock mb becomes -2091965540 and the statement mb.StringValue(Offset, s.LenB) = s gives an Out of Bounds error.