473,386 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Binary Serialization of Large ArrayList

TJO
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 3220
TJO <no@spam.com> wrote:
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));
Well that's creating a copy of the whole list to start with...
Iterating is likely to be much faster than that.
System.IO.MemoryStream ms = new System.IO.MemoryStream();

BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(ms,ptArray);

return ms.GetBuffer();


Rather than using GetBuffer, you should use ToArray - otherwise you'll
end up with it being 0-padded at the end. That may well be your current
problem.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
This will serialize a point[] array pretty much just as you have into a
memory stream, then deserialize it back into a point array.

{
Point[] ptArray = { new Point(1,1), new Point (2,2), new Point(3,3)};
//Or Point[] ptArray = (Point[])_allLines.ToArray(typeof(Point))

System.IO.MemoryStream ms = new System.IO.MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(ms, ptArray);
ptArray = null;
//Deserialize:
ms.Seek(0, System.IO.SeekOrigin.Begin);
ptArray = (Point[])formatter.Deserialize(ms);
}

--
-Philip Rieck
http://philiprieck.com/blog/

-
"TJO" <no@spam.com> wrote in message
news:O5**************@TK2MSFTNGP10.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

0
by: Esa Komulainen via .NET 247 | last post by:
Sorry if my english sucks, it's not my native language. I'm stuck with following problem: I have two vb.net (2003) applications, first one makes a list ofwords and their occurrence: Dim formatter...
3
by: Franz | last post by:
Let me describe the flow of my program first. 1. Deserialize data from xml file. 2. Addition of "PersonType" class to the AllPersonalData. 3. Serialize data back to the xml file. My question is...
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...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
2
by: Dave Veeneman | last post by:
I'm working on a project where I have to persist data to a file, rather than to a database. Basically, I need to save the state of several classes, each of which will have a couple of dozen...
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...
5
by: George Ter-Saakov | last post by:
I have 2 classes one is document and another is collection of documents. When i am trying to use XmlSerializer to serialize class which has clsDcoumentIds member variable i am getting an exception...
1
by: Eric Porter | last post by:
Help! Below is some code for a Web Service which has two methods, First() and Second(). However, when the code is run, whichever of the two methods appears second in the source fails with...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.