I have an application which i receive a stream every while to save it, so i want to create a global **FileStream** instead of creating every time i get a fil开发者_开发技巧e. Is there anyway to do that? (Is there any alternative to FileStream) can do this?
because i already have a large object(LO) in my application which affected the the CLR performance.
P.S: the incoming streams would be saved in different files(different file name)
UPDATE:
I alreay create it in using phrase but the GC.Collect is affected by the LO created in my application
If the streams need to be saved to different files i don't think there is a way of getting away from creating a new stream each time.
Having in mind what you wrote: " the incoming streams would be saved in different files" I would strongly suggest to not do that. Just create a new FileStream for every file and close as soon as you finished, as fast as you can.
Regards.
Have you tried System.IO.File.WriteAllBytes?
The FileStream object won't be very large in memory I don't think. When it flushes, the content is written to file.
To avoid touching the large object heap, you could use a List<byte[]> and chunk the bytes into predefined sizes.
加载中,请稍侯......
精彩评论