Bonjour à tous,

j'aurais voulu savoir comment améliorer les performances du code suivant :

Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
        public Byte[] Combine(params Byte[][] Arrays)
        {
            Byte[] Result = new Byte[Arrays.Sum(a => a.Length)];
            Int32 Offset = 0;
            foreach (Byte[] Array in Arrays)
            {
                System.Buffer.BlockCopy(Array, 0, Result, Offset, Array.Length);
                Offset += Array.Length;
            }
            return (Result);
        }
 
        public void Append(Byte[] Buffer)
        {
 
            if (this.Buffer == null)
                this.Buffer = Buffer;
            else
                this.Buffer = this.Combine(this.Buffer, Buffer);
        }
        public Packet TryParseBuffer(ref Int32 Length)
        {
            if (this.Buffer == null)
                return (null);
            if (this.Buffer.Length < 4)
                return (null);
            Int32 Size = BitConverter.ToInt32(this.Buffer, 0);
            Length = Size;
            if (this.Buffer.Length < Size + 4)
                return (null);
            Byte[] Content = (new MemoryStream(this.Buffer, 4, Size)).ToArray();
            Packet Packet = Packet.Deserialize(Content);
            if (this.Buffer.Length == Size + 4)
                this.Buffer = null;
            else
                this.Buffer = (new MemoryStream(this.Buffer, Size + 4, this.Buffer.Length - 4 - Size)).ToArray();
            return (Packet);
        }

C'est une application réseau, le flux en réseau local est tellement important que le buffer grandit de plus en plus ... jusqu'à qu'il y ai une OutOfMemoryException.

Merci d'avance