Best practices for reading and writing byte arrays

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Best practices for reading and writing byte arrays

Post by MaximumFirecracker »

I'm getting some slow performance when reading and writing large byte arrays using ES2. I notice in the code that ES2 seems to write and read/parse one byte at the time using a loop. Clearly, since System.IO.File.ReadAllBytes is much, much faster, ES2 should be able to read and write byte arrays very fast, too.

Is there any best practices for this? Currently, I've been using ReadArray<byte> and WriteArray<byte>, but maybe there's a better way for byte arrays?

Thank you.

All the best and Merry Xmas!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Best practices for reading and writing byte arrays

Post by Joel »

Hi there,

You should use ES2.SaveRaw and ES2.LoadRaw if you want to write bytes directly to a file.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Best practices for reading and writing byte arrays

Post by MaximumFirecracker »

I need this to be part of a ES2Writer and have it retrievable by ES2Data. Is it not possible to WriteRaw with tag?
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Best practices for reading and writing byte arrays

Post by MaximumFirecracker »

I suppose one could create a custom ES2Type wrapper class for byte[] that uses writer.WriteRaw for the byte array. Then you would be able to save byte arrays fast and with tag support.
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Best practices for reading and writing byte arrays

Post by MaximumFirecracker »

I added a custom wrapper type and some extension methods, so now I can save byte arrays fast with ES2Writer.SaveBytes and ES2Data.LoadBytes. Speedup is around 10x.

All the best.
Happy new year in advance!
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Best practices for reading and writing byte arrays

Post by Joel »

MaximumFirecracker wrote:I added a custom wrapper type and some extension methods, so now I can save byte arrays fast with ES2Writer.SaveBytes and ES2Data.LoadBytes. Speedup is around 10x.

All the best.
Happy new year in advance!
This is what I would have suggested, so glad you came across this before the Christmas break got in the way :)

Happy new year in advance to yourself also!

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked