Hallo!
Ich hab hier ein paar Funktionen:
Spoiler anzeigen
Diese serialisieren für mich ein DataTable welches dann in eine Datei gespeichert werden soll..mit Compression!
Leider ist das DataTable so groß das ich eine System.OutOfMemoryException bekomme. (ca. 4GB)
Wie kann ich den Stream oder das ByteArray aufsplitten das er mir mehrere Dateien erstellt?
Ach ja, umstellen auf 64Bit hat nichts gebracht..naja, er hängt jetzt nicht bei 3,7GB sondern erst bei 4,5GB.
System RAM: 16GB
Auslagerungsdatei: 2GB
Ich hab hier ein paar Funktionen:
VB.NET-Quellcode
- Public Shared Sub FileSerialize(ByVal File As String, ByVal Obj As Object, Optional ByVal Compress As Boolean = True, Optional ByVal EncryptKey As String = Nothing)
- Using s As New FileStream(File, FileMode.Create, FileAccess.ReadWrite)
- StreamSerialize(s, Obj, Compress, EncryptKey)
- s.Close()
- End Using
- End Sub
- Private Shared Sub StreamSerialize(ByRef s As Stream, ByVal Obj As Object, Optional ByVal Compress As Boolean = True, Optional ByVal EncryptKey As String = Nothing)
- Dim b As New Formatters.Binary.BinaryFormatter
- If Compress = True Then
- 'we want to compress this object to a byte array
- Obj = New CompressedObject(Compression.CompressByte(ByteArrSerialize(Obj)))
- End If
- If EncryptKey <> "" Then
- Obj = New EncryptedObject(Encryption.EncryptByte(ByteArrSerialize(Obj), EncryptKey))
- End If
- b.Serialize(s, Obj)
- End Sub
- Public Shared Function CompressByte(ByVal byteSource() As Byte) As Byte()
- ' Create a GZipStream object and memory stream object to store compressed stream
- Dim objMemStream As New MemoryStream()
- Dim objGZipStream As New GZipStream(objMemStream, CompressionMode.Compress, True)
- objGZipStream.Write(byteSource, 0, byteSource.Length)
- objGZipStream.Dispose()
- objMemStream.Position = 0
- ' Write compressed memory stream into byte array
- Dim buffer(CInt(objMemStream.Length)) As Byte
- objMemStream.Read(buffer, 0, buffer.Length)
- objMemStream.Dispose()
- Return buffer
- End Function
- Private Shared Function ByteArrSerialize(ByVal Obj As Object) As Byte()
- Using MS As New MemoryStream
- Dim BF As New Formatters.Binary.BinaryFormatter
- BF.Serialize(MS, Obj)
- ByteArrSerialize = MS.ToArray
- MS.Close()
- End Using
- End Function
- <Serializable()>
- Private Class CompressedObject
- Public CompressedObject As Byte()
- Public Sub New(ByVal CompressedObject As Byte())
- Me.CompressedObject = CompressedObject
- End Sub
- End Class
- <Serializable()>
- Private Class EncryptedObject
- Public EncryptedObject As Byte()
- Public Sub New(ByVal EncryptedObject As Byte())
- Me.EncryptedObject = EncryptedObject
- End Sub
- End Class
Diese serialisieren für mich ein DataTable welches dann in eine Datei gespeichert werden soll..mit Compression!
Leider ist das DataTable so groß das ich eine System.OutOfMemoryException bekomme. (ca. 4GB)
Wie kann ich den Stream oder das ByteArray aufsplitten das er mir mehrere Dateien erstellt?
Ach ja, umstellen auf 64Bit hat nichts gebracht..naja, er hängt jetzt nicht bei 3,7GB sondern erst bei 4,5GB.
System RAM: 16GB
Auslagerungsdatei: 2GB