J
James
I am using vb.net and need to keep in memory a large data structure, so I am
looking for the best option. And after several test I am pretty confused. So
I will be grateful if anyone can help me.
My basic need is:
Keep an "array" (or other structure) of pointers to "arrays" (or other
structure) of bytes. Example:
arrayPointer(1,000,000) each one point to arraByte1(), arrayByte2(),
arrayByte3().., arrayByte1000000().
So it is possible to redim each arrayByte() to the dimension I need.
I supposed that a configuration like the above (suppose each arrayByte hold
1 Byte) needs:
Pointers: 4 bytes x 1 Million = 4 Mb
Arrays: 1 byte per array x 1 Million arrays = 1 Mb
I have trying different option and I obtained a very high memory
comsumption, is there any way to keep memory low and achieve what I need?,
I am using "GC.GetTotalMemory(True)" to find out the memory usage is that
right?
Array of structures
Public Structure stbyte
Public byt() As Byte
End Structure
Memory = GC.GetTotalMemory(True)
Dim intPo(1000000) As stbyte ' 1 Million structures
For intI = 1 To 1000000
ReDim intPo(intI - 1).byt(0) ' Redim to 1 byte each
Next
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory= 20 Mbytes
Jagged Array of Bytes
Memory = GC.GetTotalMemory(True)
Dim bytes(1000000)() As Byte ' 1 Million Jagged array
For intI = 1 To 1000000
ReDim bytes(intI - 1)(1) ' Each vector to 1 byte
Next
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory= 20 Mbytes
Rectangular Array of Bytes
Memory = GC.GetTotalMemory(True)
Dim bytes(1000000, 0) As Byte ' 1 Million array of 1 byte each
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory = 1 Mbytes (but in this case I can not redim each row).
Array of BitsArrays
Memory = GC.GetTotalMemory(True)
Dim bitArray(1000000) As BitArray ' 1 Million bitarrays
For intI = 1 To 1000000
bitArray(intI - 1) = New BitArray(8) ' Each bitarray 8 bits
Next
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory = 40 Mbytes
looking for the best option. And after several test I am pretty confused. So
I will be grateful if anyone can help me.
My basic need is:
Keep an "array" (or other structure) of pointers to "arrays" (or other
structure) of bytes. Example:
arrayPointer(1,000,000) each one point to arraByte1(), arrayByte2(),
arrayByte3().., arrayByte1000000().
So it is possible to redim each arrayByte() to the dimension I need.
I supposed that a configuration like the above (suppose each arrayByte hold
1 Byte) needs:
Pointers: 4 bytes x 1 Million = 4 Mb
Arrays: 1 byte per array x 1 Million arrays = 1 Mb
I have trying different option and I obtained a very high memory
comsumption, is there any way to keep memory low and achieve what I need?,
I am using "GC.GetTotalMemory(True)" to find out the memory usage is that
right?
Array of structures
Public Structure stbyte
Public byt() As Byte
End Structure
Memory = GC.GetTotalMemory(True)
Dim intPo(1000000) As stbyte ' 1 Million structures
For intI = 1 To 1000000
ReDim intPo(intI - 1).byt(0) ' Redim to 1 byte each
Next
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory= 20 Mbytes
Jagged Array of Bytes
Memory = GC.GetTotalMemory(True)
Dim bytes(1000000)() As Byte ' 1 Million Jagged array
For intI = 1 To 1000000
ReDim bytes(intI - 1)(1) ' Each vector to 1 byte
Next
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory= 20 Mbytes
Rectangular Array of Bytes
Memory = GC.GetTotalMemory(True)
Dim bytes(1000000, 0) As Byte ' 1 Million array of 1 byte each
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory = 1 Mbytes (but in this case I can not redim each row).
Array of BitsArrays
Memory = GC.GetTotalMemory(True)
Dim bitArray(1000000) As BitArray ' 1 Million bitarrays
For intI = 1 To 1000000
bitArray(intI - 1) = New BitArray(8) ' Each bitarray 8 bits
Next
Memory = GC.GetTotalMemory(True) - Memory
Memory = Memory / 1000000
I obtained Memory = 40 Mbytes