In my small little file transfer website (this one, running .NET 4.5.1) I'm following the Microsoft Knowledge Base article 812406 to send previously uploaded files from the server to the browser.
Doing performance optimization I was suprised to find that the line
var buffer = new byte[10000];
takes a considerable percentage of time (I'm using Red Gate's ANTS Performance Profiler). The buffer is only allocated once per full download/client.
My questions:
- Is it good practice to allocate a buffer this way and this size?
- Any alternatives on allocating a ≈10k buffer?
Update 1:
Thanks to your comments I've seen that the memory is allocated inside the loop, too.
Still, ANTS Profiler only marks that allocation outside of the loop to take that much time, which I honestly do not understand (yet). I have removed the (meaningless) allocation inside the loop.
Update 2:
Having implemented the suggested BufferManager
and also reduced the buffer size from 10k down to 4096 (just in case...), my website runs very smooth since days.
buffer= new Byte[10000];
inside the loop is completely superfluous. I would simply drop it; – GallagerBufferManager
thing and see, what the profiler tells me. – Inga