Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2006

Tip: Looking for answers? Try searching our database.

Are there any pure managed object to Byte Array methods?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Varn - 03 Nov 2006 22:30 GMT
I want to translate an objects data to a byte array and vice-versa.  The
closest thing I found is Marshal.StructureToPtr(), and
Marshal.PtrToStructure().  However, these functions are meant to copy from
managed objects to unmanaged IntPtrs.

Is there an equivalent call that does a pure managed to managed byte array
copy to and from an object?

Signature

-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

Ben Voigt - 03 Nov 2006 23:57 GMT
>I want to translate an objects data to a byte array and vice-versa.  The
> closest thing I found is Marshal.StructureToPtr(), and
[quoted text clipped - 3 lines]
> Is there an equivalent call that does a pure managed to managed byte array
> copy to and from an object?

There's the BitConverter class, you'll have to do your own layout.  If you
need to capture anything beyond binary numeric data (class type or
handle-linked structures), you're probably looking toward serialization
instead.
Ken Varn - 06 Nov 2006 15:17 GMT
The only problem that I have with serialization is the volume of data that
results from serializing a class object.  I was hoping to just be able to
extract an array of bytes from the class object data.  BitConverter only
works on primitive types.

I put together my own class to do this, but wanted to make sure it was not
already available.

Basically what I did was encapsulate the Marshal.PtrToStructure() and
Marshal.StructureToPtr() methods to do the translation via pinned objects to
and from a Byte Array.  It seems to work pretty well, but I was not sure if
I was duplicating something that was already available.

Signature

-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------

>I want to translate an objects data to a byte array and vice-versa.  The
> closest thing I found is Marshal.StructureToPtr(), and
[quoted text clipped - 3 lines]
> Is there an equivalent call that does a pure managed to managed byte array
> copy to and from an object?

There's the BitConverter class, you'll have to do your own layout.  If you
need to capture anything beyond binary numeric data (class type or
handle-linked structures), you're probably looking toward serialization
instead.
Ben Voigt - 06 Nov 2006 17:25 GMT
> The only problem that I have with serialization is the volume of data that
> results from serializing a class object.  I was hoping to just be able to
> extract an array of bytes from the class object data.  BitConverter only
> works on primitive types.

Yes, I think serialization is overkill for most purposes, it's geared toward
schema versioning and reconstructing object graphs with cycles.

> I put together my own class to do this, but wanted to make sure it was not
> already available.
[quoted text clipped - 20 lines]
> handle-linked structures), you're probably looking toward serialization
> instead.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.