Re: Write class/struct object to file
- From: Ashutosh <smbs_user@xxxxxxxxxxxxxxxx>
- Date: Mon, 28 Jan 2008 20:28:38 +0530
Hi Samuel\Steven,
Yes, I am trying to match the format used by another application. So,
for that I don't think that Binary Serialization will do.
Well I thought .NET made everything easy...but to do this...its
difficult.
Regards,
Ashutosh
Steven Cheng[MSFT] wrote:
Thanks for Sam's input..
Hi Ashutosh,
In .net framework, the code can not directly access memory which is totally different from c/c++. That means you can not write out class/struct objects into memory/file through their point/address. If you want to persist some class objects into memory or file(in binary format), you can use the Binary Serialization feature as Sam suggested.
To do binary serialziation on class, you need to first make the certain class serializable and then use Binary Serializer to serialize the instances of those classes. You can serialize them into memoryStream or fileStream.
Here are some articles introducing .net binary serialization:
#Binary Serialization
http://msdn2.microsoft.com/en-us/library/72hyey7b(VS.71).aspx
#Run-time Serialization http://msdn.microsoft.com/msdnmag/issues/02/04/net/
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
From: Samuel R. Neff <samuelneff@xxxxxxxxxx>of
Subject: Re: Write class/struct object to file
Date: Fri, 25 Jan 2008 17:20:54 -0500
Are you trying to match a format used by another application or simply
store a class/struct as binary data? If the latter, then
BinaryFormatter to Serialize/Deserialize the object to/form the
stream.
HTH,
Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Sat, 19 Jan 2008 02:29:29 +0530, "Ashutosh"
<smbs_user@xxxxxxxxxxxxxxxx> wrote:
Hi,
How can I create a fixed size class or structure which consist of membersclassany types and strings of fixed (specified) sizes. I need to write thearray/stringobject by using a BinaryStream....
I need to keep the code fully managed. I tried to declare theuseof fixed size, but the compiler says to make to code unmanaged/unsafe orMarshal attributes. I know how to use those attributes, but as far as I think they doesn't make sense here...
Actually I am looking for something similar to this in C++
---------------------------------------------------------
CFile f;
f.Open(....);
struct someStruct s1;
f.Write((char*)&s1,sizeof(s1));
---------------------------------------------------------
Any ideas how I can achieve the same in C# with minimal effort?
Regards,
Ashutosh
- Follow-Ups:
- Re: Write class/struct object to file
- From: Steven Cheng[MSFT]
- Re: Write class/struct object to file
- From: Jon Skeet [C# MVP]
- Re: Write class/struct object to file
- References:
- Re: Write class/struct object to file
- From: Samuel R . Neff
- Re: Write class/struct object to file
- From: Steven Cheng[MSFT]
- Re: Write class/struct object to file
- Prev by Date: Re: Get class- and functionname
- Next by Date: Huge xml files
- Previous by thread: Re: Write class/struct object to file
- Next by thread: Re: Write class/struct object to file
- Index(es):