PC Review


Reply
Thread Tools Rate Thread

Custom file DeSerialization and file access

 
 
=?Utf-8?B?TmFkYXY=?=
Guest
Posts: n/a
 
      2nd Jan 2005
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
 
Reply With Quote
 
 
 
 
Sahil Malik
Guest
Posts: n/a
 
      2nd Jan 2005
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" <(E-Mail Removed)> wrote in message
news:F6964180-F032-431B-B09A-(E-Mail Removed)...
> 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



 
Reply With Quote
 
=?Utf-8?B?TmFkYXY=?=
Guest
Posts: n/a
 
      3rd Jan 2005
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" <(E-Mail Removed)> wrote in message
> news:F6964180-F032-431B-B09A-(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Sahil Malik
Guest
Posts: n/a
 
      3rd Jan 2005
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" <(E-Mail Removed)> wrote in message
news:EDDD8B7A-E569-40EE-B235-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
>> news:F6964180-F032-431B-B09A-(E-Mail Removed)...
>> > 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

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to reliably detect a text file's encoding for XML deserialization Marc Scheuner Microsoft C# .NET 4 9th Apr 2006 03:18 PM
File Manager Application With Custom File Access wdweb Microsoft ASP .NET 0 10th Mar 2006 04:06 PM
How to access a custom dll file in .Net =?Utf-8?B?UGF1bCBQaGlsbGlwcw==?= Microsoft Dot NET 0 13th Jan 2005 04:29 PM
Custom file DeSerialization =?Utf-8?B?TmFkYXY=?= Microsoft C# .NET 2 6th Jan 2005 03:43 PM
Question: Invoking custom file type (file associated with custom app) VB Programmer Microsoft ASP .NET 1 3rd Nov 2003 11:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:15 PM.