Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

BufferedFileReader & BufferedFileWriter: extending BinaryReader and BinaryWriter using BufferedStream

, 17 Dec 2011
Rate this:
Please Sign up or sign in to vote.
Hi Olivier,First, thank you for your helpful post here and I'd like introduce some suggestion that might help to increase the performance of the Read & Write methods (of arrays such as ReadIntArray, ReadFloatArray and WriteIntArray, .... etc.). My suggestion is to make use of the...
Hi Olivier,
 
First, thank you for your helpful post here and I'd like introduce some suggestion that might help to increase the performance of the Read & Write methods (of arrays such as ReadIntArray, ReadFloatArray and WriteIntArray, .... etc.). My suggestion is to make use of the System.Buffer.BlockCopy() that can be used to copy the items from some numeric type array to another one. For example, your ReadIntArray() code might be replaced by:
 
public int[] ReadIntArray(int length)
{
    int[] array = new int[length];
    byte[] bytes = ReadBytes(length * 4);
    System.Buffer.BlockCopy(bytes, 0, array, 0, array.Length);
    return array;
}
 
and the WriteIntArray() should be replaced by:
 
public void Write(int[] array)
{
    byte[] bytes = new byte[4 * array.Length];
    System.Buffer.BlockCopy(array, 0, bytes, 0, bytes.Length);
    Write(bytes);
}
 
I hope that will help... and thanks again for your great post.
 
Ragheed

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ragheed Al-Tayeb
Team Leader Hawk International for Finance & Construction Ltd.
Yemen Yemen
Bachelor degree of Computer Sciences, Software developer using .NET (Visual Basic & C#).
I like the development of an Artificial Intelligence Systems, GPS Applications, GDI+, APIs, N-Tier Applications, Distributed Systems and Network Monitoring Systems.
Mobile Development (Windows Mobile & Android).

Comments and Discussions

 
GeneralReason for my vote of 5 You are absolutely right. I've never... PinmemberOlivier Levrey11-Dec-11 21:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 17 Dec 2011
Article Copyright 2011 by Ragheed Al-Tayeb
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid