473,395 Members | 1,495 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,395 software developers and data experts.

Custom file DeSerialization and file access

Hi,

I have to read files generated by 3rd party application, these files are in
a propriotary format ( not generated using the .NET framework ), I want to
implement a custom DeSerializer to read the data in the file, I wonder is it
possible to read files in this manner ( e.g. custom implementation of the
ISerializable interface )? is this right way to extract data from the file?
OR should I rather 'manually' use the FileStream to read the desiered chunks
of data?

Another Issue, is there a C# equivalent to the unmanaged CreateFileMapping,
MapViewOfFile ??? accessing files in this manner dramatically impove
performance as the kernel is resposible for loading the data from the disk (
and not the application ) so less context switch are done between the
application layer and the kernel...

--
Nadav
http://www.ddevel.com
Nov 16 '05 #1
3 2438
Nadav,

While this certainly could be acheived using ISerializable, there is no
point in doing so. ISerializable's purpose is to implement custom
serialization - so that IFormatter (BinaryFormatter for example), can call
the proper constructor and the proper GetObjectData - in your case you are
probably better off implementing the "deserialization" to .NET via a non
ISerializable or Serializable mechanism.

Secondly,

Kernel32.Dll->CreateFileMapping and
Kernel32.Dll->MapViewOfFile ..

AFAIK donot have managed implementations.

But they can be easily used in C# like this --

[DllImport("kernel32.dll", SetLastError=true)]
static extern IntPtr CreateFileMapping(IntPtr hFile,
IntPtr lpFileMappingAttributes, PageProtection flProtect, uint
dwMaximumSizeHigh,
uint dwMaximumSizeLow, string lpName);

and

[DllImport("kernel32.dll")]
static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow,
UIntPtr dwNumberOfBytesToMap);

TTFN :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Hi,

I have to read files generated by 3rd party application, these files are
in
a propriotary format ( not generated using the .NET framework ), I want to
implement a custom DeSerializer to read the data in the file, I wonder is
it
possible to read files in this manner ( e.g. custom implementation of the
ISerializable interface )? is this right way to extract data from the
file?
OR should I rather 'manually' use the FileStream to read the desiered
chunks
of data?

Another Issue, is there a C# equivalent to the unmanaged
CreateFileMapping,
??? accessing files in this manner dramatically impove
performance as the kernel is resposible for loading the data from the disk
(
and not the application ) so less context switch are done between the
application layer and the kernel...

--
Nadav
http://www.ddevel.com

Nov 16 '05 #2
Sahil,

Thanks for you immediate responce, concerning the FileMapping issue, indeed
it is possible to use these APIs through DllImport BUT all access to the
mapped data would have to be done in an unsafe manner, therefor it is not
posibble to reffer to the mapped data directly as can be done in C++ ( by
pointers ), my guess is that usage of the file mapping API should be done
only in the unmanaged world....

Nadav.

"Sahil Malik" wrote:
Nadav,

While this certainly could be acheived using ISerializable, there is no
point in doing so. ISerializable's purpose is to implement custom
serialization - so that IFormatter (BinaryFormatter for example), can call
the proper constructor and the proper GetObjectData - in your case you are
probably better off implementing the "deserialization" to .NET via a non
ISerializable or Serializable mechanism.

Secondly,

Kernel32.Dll->CreateFileMapping and
Kernel32.Dll->MapViewOfFile ..

AFAIK donot have managed implementations.

But they can be easily used in C# like this --

[DllImport("kernel32.dll", SetLastError=true)]
static extern IntPtr CreateFileMapping(IntPtr hFile,
IntPtr lpFileMappingAttributes, PageProtection flProtect, uint
dwMaximumSizeHigh,
uint dwMaximumSizeLow, string lpName);

and

[DllImport("kernel32.dll")]
static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow,
UIntPtr dwNumberOfBytesToMap);

TTFN :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
Hi,

I have to read files generated by 3rd party application, these files are
in
a propriotary format ( not generated using the .NET framework ), I want to
implement a custom DeSerializer to read the data in the file, I wonder is
it
possible to read files in this manner ( e.g. custom implementation of the
ISerializable interface )? is this right way to extract data from the
file?
OR should I rather 'manually' use the FileStream to read the desiered
chunks
of data?

Another Issue, is there a C# equivalent to the unmanaged
CreateFileMapping,
??? accessing files in this manner dramatically impove
performance as the kernel is resposible for loading the data from the disk
(
and not the application ) so less context switch are done between the
application layer and the kernel...

--
Nadav
http://www.ddevel.com


Nov 16 '05 #3
Nadav,

Good news. You can do pointer operations in C# using the unsafe keyword. I
am using Kernel32.dll->MoveMemory happily in a heavily used caching block I
wrote for a windows service that gets hit a few thousand times a second in
an enterprise block.

You have to compile this with the /unsafe option, but it works.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
Sahil,

Thanks for you immediate responce, concerning the FileMapping issue,
indeed
it is possible to use these APIs through DllImport BUT all access to the
mapped data would have to be done in an unsafe manner, therefor it is not
posibble to reffer to the mapped data directly as can be done in C++ ( by
pointers ), my guess is that usage of the file mapping API should be done
only in the unmanaged world....

Nadav.

"Sahil Malik" wrote:
Nadav,

While this certainly could be acheived using ISerializable, there is no
point in doing so. ISerializable's purpose is to implement custom
serialization - so that IFormatter (BinaryFormatter for example), can
call
the proper constructor and the proper GetObjectData - in your case you
are
probably better off implementing the "deserialization" to .NET via a non
ISerializable or Serializable mechanism.

Secondly,

Kernel32.Dll->CreateFileMapping and
Kernel32.Dll->MapViewOfFile ..

AFAIK donot have managed implementations.

But they can be easily used in C# like this --

[DllImport("kernel32.dll", SetLastError=true)]
static extern IntPtr CreateFileMapping(IntPtr hFile,
IntPtr lpFileMappingAttributes, PageProtection flProtect, uint
dwMaximumSizeHigh,
uint dwMaximumSizeLow, string lpName);

and

[DllImport("kernel32.dll")]
static extern IntPtr MapViewOfFile(IntPtr hFileMappingObject, uint
dwDesiredAccess, uint dwFileOffsetHigh, uint dwFileOffsetLow,
UIntPtr dwNumberOfBytesToMap);

TTFN :-)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:F6**********************************@microsof t.com...
> Hi,
>
> I have to read files generated by 3rd party application, these files
> are
> in
> a propriotary format ( not generated using the .NET framework ), I want
> to
> implement a custom DeSerializer to read the data in the file, I wonder
> is
> it
> possible to read files in this manner ( e.g. custom implementation of
> the
> ISerializable interface )? is this right way to extract data from the
> file?
> OR should I rather 'manually' use the FileStream to read the desiered
> chunks
> of data?
>
> Another Issue, is there a C# equivalent to the unmanaged
> CreateFileMapping,
> ??? accessing files in this manner dramatically impove
> performance as the kernel is resposible for loading the data from the
> disk
> (
> and not the application ) so less context switch are done between the
> application layer and the kernel...
>
> --
> Nadav
> http://www.ddevel.com


Nov 16 '05 #4

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

Similar topics

0
by: psy000 | last post by:
Hi, I have a C# web service client that talks to a JAVA application sever. I use AXIS to generate the WSDL file, use wsdl.exe to generate proxy stub c# code. When I try to use c# client connect...
1
by: Mark Overstreet | last post by:
Hi, I have several custom collections that inherit from System.Collections.Specialized.NameObjectCollectionBase and I want to serialize and deserialize with the XMLSerializer object. This works...
2
by: Nadav | last post by:
Hi, Introduction: **************** I am trying to DeSerialize a file that was created by an unmanaged application by the binary formatter, to achieve that I am implementing the following...
6
by: Whoever | last post by:
Here's what I have A custom collection: public class aUser { public string UserName { get {...} set {...} } public class UserList : System.Collection.CollectionBase { public void Add(aUser...
5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
4
by: Marc Scheuner | last post by:
Folks, I have a text file which contains some XML. In its XML header, it claims to be of UTF-8 encoding - however, it's really not, it's a ANSI / Windows-1252 / ISO-8859-1 encoding. Trouble...
3
by: Zachary Turner | last post by:
Hello, I have a situation where I would like to perform custom serialization and deserialization of an existing .NET framework object (specifically, System.DateTime). Is there a common paradigm...
4
by: Val | last post by:
I have a complex object that I need to serialize. Rather than rely on a standard routine, which is called during the serialization/deserialization, I would like to be able to use my own functions...
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
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: 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
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.