Re: Structure to Byte array
Here is a link to some stuff in regards to Marshaling ;)
Marshaling Structures
Re: Structure to Byte array
If you're wanting to go to a file and nothing else other than your program needs to read the resulting file, why don't you use binary serialization? It would be a lot easier to implement.
Re: Structure to Byte array
I agree with bgmacaw, binary serialization takes about two lines to implement, and you need to add the <Serializable()> attribute to the structure definition.
Re: Structure to Byte array
I'm trying to serialize about 3-16 mb worth of byte arrays. I figured it would be faster to copy it from memory to the harddrive rather than 1) use reflection to list all the public/private fields 2) use reflection to ascertain the values of the fields 3) watch for duplicate references and circular references and 4) dump the whole thing to a file.
I've tried binary serialization. Too slow and/or "OutOfMemoryException".
I'd rather create a byte array at the same location in memory as the structure and read it to an IO.Stream.
Yes, I'm aware that you can only do this with value types (i.e. structures). I'm not using any classes for the data I'm saving... only structures.
Re: Structure to Byte array
I have used serialization to serialize and deserialize a 2MB - 25MB file and it was fast enought to not notice any lag ect when working with the smaller files and only a verry small amount of lag when dealing with the larger files. Also you shouldnt get an out of memory exception when working with files of that size, are you sure you closed the streams etc...
Re: Structure to Byte array
Quote:
Originally Posted by agent
I've tried binary serialization. Too slow and/or "OutOfMemoryException".
I agree that it sounds like something didn't get released properly. I've done serialization for web services on files up to 150mb without any hitches.
Re: Structure to Byte array
I'd also be interested in using a progress bar without having to deal with ISerializable.
A couple of the data I'm working with are stored as byte arrays already. Maybe I'll write an IBytes interface to implement a Bytes() as Byte property and just switch to classes that implement this...
Re: Structure to Byte array
Thats A good Idea, I usually have a SaveToFile method in my serializable classes, but your Idea of returning the bytes is a much better Idea, as then the SaveToFile can just call the getBytes method and save them to file, makes for a bit more functionality I think, Thanks for the idea...