TizzyT

StorageArray -TizzyT

Apr 1st, 2015
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.71 KB | None | 0 0
  1. 'Byte Array 2GB limit workaround
  2.    Public Structure StorageArray
  3.         Private MGR As List(Of Byte())
  4.         Private Tail() As Byte
  5.         Private WholeElements As Integer
  6.         Private _Length As Long
  7.         Public ReadOnly Property Length() As Long
  8.             Get
  9.                 Return _Length
  10.             End Get
  11.         End Property
  12.         Public Sub New(ByVal size As Long)
  13.             _Length = size + 1
  14.             Dim cnt As Long = Math.Ceiling(_Length / 2147483591)
  15.             Dim rmd As Integer = _Length Mod 2147483591
  16.             If cnt <= 1 Then
  17.                 Tail = New Byte(size) {}
  18.             Else
  19.                 WholeElements = cnt - 1
  20.                 MGR = New List(Of Byte())
  21.                 For i = 1 To WholeElements
  22.                     MGR.Add(New Byte(2147483590) {})
  23.                 Next
  24.                 If rmd > 0 Then Tail = New Byte(rmd - 1) {}
  25.             End If
  26.         End Sub
  27.         Default Public Property Bytes(ByVal index As Long) As Byte
  28.             Get
  29.                 index += 1
  30.                 Dim cnt As Integer = Math.Ceiling(index / 2147483591) - 1
  31.                 Dim rmd As Integer = (index Mod 2147483591) - 1
  32.                 If rmd < 0 Then rmd = 0
  33.                 If cnt >= WholeElements Then Return Tail(rmd) Else Return MGR(cnt)(rmd)
  34.             End Get
  35.             Set(value As Byte)
  36.                 index += 1
  37.                 Dim cnt As Integer = Math.Ceiling(index / 2147483591) - 1
  38.                 Dim rmd As Integer = (index Mod 2147483591) - 1
  39.                 If rmd < 0 Then rmd = 0
  40.                 If cnt >= WholeElements Then Tail(rmd) = value Else MGR(cnt)(rmd) = value
  41.             End Set
  42.         End Property
  43.     End Structure
Advertisement
Add Comment
Please, Sign In to add comment