473,467 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Binary Serialization of Array

I need a quick way to binary serialize an ArrayList of System.Drawing.Point
objects. There are a lot of point is this list so I am trying to avoid
iterating over them. I have tried the following but cannot find an easy way
to Deserialize the data. Can anyone suggest a better way?

Array ptArray = _allLines.ToArray(typeof(System.Drawing.Point));
System.IO.MemoryStream ms = new System.IO.MemoryStream();

BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(ms,ptArray);
return ms.GetBuffer();
Nov 16 '05 #1
2 10160
To deserialize, you can take the byte array, and do this:

// Create a stream wrapping the byte array.
using (MemoryStream ms = new MemoryStream(buffer))
{
// Create a formatter.
IFormatter formatter = new BinaryFormatter();

// Deserialize.
Point[] points = (Point[]) formatter.Deserialize(ms);
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"news.microsoft.com" <no@spam.com> wrote in message
news:em**************@TK2MSFTNGP15.phx.gbl...
I need a quick way to binary serialize an ArrayList of System.Drawing.Point
objects. There are a lot of point is this list so I am trying to avoid
iterating over them. I have tried the following but cannot find an easy
way to Deserialize the data. Can anyone suggest a better way?

Array ptArray = _allLines.ToArray(typeof(System.Drawing.Point));
System.IO.MemoryStream ms = new System.IO.MemoryStream();

BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(ms,ptArray);
return ms.GetBuffer();

Nov 16 '05 #2
TJO
Thank you so much for that very nice approach!!!!

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:u1**************@TK2MSFTNGP14.phx.gbl...
To deserialize, you can take the byte array, and do this:

// Create a stream wrapping the byte array.
using (MemoryStream ms = new MemoryStream(buffer))
{
// Create a formatter.
IFormatter formatter = new BinaryFormatter();

// Deserialize.
Point[] points = (Point[]) formatter.Deserialize(ms);
}

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"news.microsoft.com" <no@spam.com> wrote in message
news:em**************@TK2MSFTNGP15.phx.gbl...
I need a quick way to binary serialize an ArrayList of
System.Drawing.Point objects. There are a lot of point is this list so I
am trying to avoid iterating over them. I have tried the following but
cannot find an easy way to Deserialize the data. Can anyone suggest a
better way?

Array ptArray = _allLines.ToArray(typeof(System.Drawing.Point));
System.IO.MemoryStream ms = new System.IO.MemoryStream();

BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(ms,ptArray);
return ms.GetBuffer();


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet...
2
by: phyzics | last post by:
I am porting an application from C++ to C#, and am having trouble finding a way to quickly and efficiently write structures to a binary file. In C++ this is trivial because all that is necessary is...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.