473,471 Members | 4,625 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

STL.NET serialization

This is a follow on from my previous thread about clr/safe and STL.NET

http://groups.google.com/group/micro...70a89dbc67c332

A more specific problem now is migrating the current MFC serialization
onto STL serialization?

How best to serilize using STL?

STL does not seem to directly support the concept of serialization in
the basic STL library?

Given i have managed to serialise using STL, is this then going to be
compatible with STL.NET?

More precisly if i have managed to 'save' a set of vectors, maps etc of
int, long string etc
using STL.

Is this stream going to 'load' into STL.NET equivalent classes?

Also is streaming and the concept of serialization going to be
verifiable?

Any good links relative to this subject would be greatly appreciated?
Thanks in advance.

Nov 23 '05 #1
15 1999
Herby wrote:
This is a follow on from my previous thread about clr/safe and STL.NET

http://groups.google.com/group/micro...70a89dbc67c332

A more specific problem now is migrating the current MFC serialization
onto STL serialization?

How best to serilize using STL?
The C++ standard library does not include any support for serialization at
all. You might be able to use boost::serialization from www.boost.org.
STL does not seem to directly support the concept of serialization in
the basic STL library?
Correct.
Given i have managed to serialise using STL, is this then going to be
compatible with STL.NET?
Unlikely, but it depends on how you did it.
More precisly if i have managed to 'save' a set of vectors, maps etc
of
int, long string etc
using STL.

Is this stream going to 'load' into STL.NET equivalent classes?
Only you can say.
Also is streaming and the concept of serialization going to be
verifiable?
Only you can say, since you implemented the serialization.
Any good links relative to this subject would be greatly appreciated?


I haven't seen any. Post 'em if you get 'em.

-cd
Nov 23 '05 #2
Cheers Carl.

More specific question.

If i use the IOStream classes present in the standard C++ library are
these going to be available in STL.NET?

If i use Boost to do my serialisation, which would be the natural
choice( dont want to re-invent the wheel ) is this going to be
compatible with STL.NET ?

Nov 23 '05 #3
Herby wrote:
Cheers Carl.

More specific question.

If i use the IOStream classes present in the standard C++ library are
these going to be available in STL.NET?
I don't know.

If i use Boost to do my serialisation, which would be the natural
choice( dont want to re-invent the wheel ) is this going to be
compatible with STL.NET ?


Very unlikely.

-cd
Nov 23 '05 #4
I want to stay in the realms of C++\CLI and STL.NET as possible.
How can i do file input/output or more specifically serialization
within this boundary?

Am i now forced to use the .NET framework classes to achieve this?

Thanks.

Nov 23 '05 #5
Herby wrote:
I want to stay in the realms of C++\CLI and STL.NET as possible.
How can i do file input/output or more specifically serialization
within this boundary?

Am i now forced to use the .NET framework classes to achieve this?


I think with the .NET framework you can automatically serialize
containers, STL.NET or otherwise (I assume the mechanism uses
reflection, like Java serialization). If your code doesn't need to be
portable to ordinary C++, this would appear to be your best option,
assuming testing shows it to be fast enough for your needs.

Tom
Nov 24 '05 #6
Tom.

I need to serialize from a current un-managed application
I then want to de-serialize this into a new managed application.

This serialized file is then the bridge between the old un-managed
application and the new managed application.

We want the new managed application to be backward portable to C++\STL(
as much as possible) consequently this is why we are writing the new
application in C++\CLI and STL\CLR.

The new application must be 100% verifiable.

We will only use .NET specifics ( framework classes ) where these is no
viable compatible C++\STL solution.
Performance is also critical in terms of loading these files and the
space they take up on disk.

So it seems to me now i will write a custom serialize mechanism in the
source un-managed application.
So i cannot use the inbuilt .NET serialization mechanism because it
will not understand my serialized file format.

And then write a custom de-serialize mechanism in the new application.

The IOStream classes are not going to be ported to STL\CLR.

So here it would seem i am forced to use .NET to de-serialize my
file????
What class should i use?

Thanks.

Nov 24 '05 #7
Herby wrote:
Tom.

I need to serialize from a current un-managed application
I assume this code hasn't been written yet?
I then want to de-serialize this into a new managed application.

This serialized file is then the bridge between the old un-managed
application and the new managed application.
You might be able to bridge them by creating a mixed-mode application,
but it's not clear without knowing the details of what and why you are
switching from Win32 to CLR.
We want the new managed application to be backward portable to C++\STL(
as much as possible) consequently this is why we are writing the new
application in C++\CLI and STL\CLR.

The new application must be 100% verifiable.

We will only use .NET specifics ( framework classes ) where these is no
viable compatible C++\STL solution.
Performance is also critical in terms of loading these files and the
space they take up on disk.

So it seems to me now i will write a custom serialize mechanism in the
source un-managed application.
So i cannot use the inbuilt .NET serialization mechanism because it
will not understand my serialized file format.
Any reason for this? Can't you make the un-managed application mixed
mode, with the serialization code using .NET? Also, note that
System.Runtime.Serialization seems quite configurable, so you might be
able to get it to read in your format, if you define the format with
this in mind.
And then write a custom de-serialize mechanism in the new application.

The IOStream classes are not going to be ported to STL\CLR.

So here it would seem i am forced to use .NET to de-serialize my
file????
What class should i use?


BinaryReader, if your binary format uses little endian byte order and
you don't end up using .NET serialization.

Tom
Nov 24 '05 #8
Thanks Tom.

Its possible the source un-managed application could use mixed mode.
Ultimately the source application will move to .NET too, initially via
mixed mode.
I would only want the serialization code to be managed and not attempt
to compile everything else to managed via "IJW"?

Nov 24 '05 #9
Herby wrote:
Thanks Tom.

Its possible the source un-managed application could use mixed mode.
Ultimately the source application will move to .NET too, initially via
mixed mode.
I would only want the serialization code to be managed and not attempt
to compile everything else to managed via "IJW"?


Over to Carl or someone else, since I've never written anything in
C++/CLI or managed C++ I'm afraid.

Tom
Nov 24 '05 #10
JAL
Herby... Having written in C++/cli for one week, I can confidently say :)

You could write a bridge class that implements a custom interface say IData.
Provide a method that converts your unmanaged data to managed data and wraps
them in a concrete class MyData of type IData, marked [Serializable]. Write a
IVersion and IData interface and compile this into a pure MSIL
MyInterface.dll. In your mixed C++/cli application reference the dll as using
"MyInterface.dll". In your mixed mode class provide a method ToManagedData
that takes an unmanaged data object and returns an instance of your managed
MyData class. Create a concrete class MyVersion of type IVersion. Use
binaryformatter to serialize MyVersion and then MyData to a file. Then in a
C# class open the file, deserialize the MyVersion object, check for the
correct version and then deserialize the MyData object.

Of course, it would be a lot easier if STL.NET emits classes that are marked
[Serializable], but then since I cannot download it yet, I cannot say.

"Herby" wrote:
Tom.

I need to serialize from a current un-managed application
I then want to de-serialize this into a new managed application.

This serialized file is then the bridge between the old un-managed
application and the new managed application.

We want the new managed application to be backward portable to C++\STL(
as much as possible) consequently this is why we are writing the new
application in C++\CLI and STL\CLR.

The new application must be 100% verifiable.

We will only use .NET specifics ( framework classes ) where these is no
viable compatible C++\STL solution.
Performance is also critical in terms of loading these files and the
space they take up on disk.

So it seems to me now i will write a custom serialize mechanism in the
source un-managed application.
So i cannot use the inbuilt .NET serialization mechanism because it
will not understand my serialized file format.

And then write a custom de-serialize mechanism in the new application.

The IOStream classes are not going to be ported to STL\CLR.

So here it would seem i am forced to use .NET to de-serialize my
file????
What class should i use?

Thanks.

Nov 24 '05 #11
Ok, im changing my thinking from pesimistic to optimistic and this has
illuminated a solution.

My new runtime application will mostly use C++\CLI and STL\CLR and use
..NET specifics for things like serialization etc.
I will assume under .NET peformance will not suffer too much and it
will be accepted, thus removing the need to compile this to un-managed
for some clients( pessimistic view ). If the pessimistic view turns out
to be right then some parts of the system will have to have an
un-managed replacement, such as writing my own DIY serialisation using
SCL streams and .NET BinaryReader classes.

My design-time applicaton will then use mixed mode compilation and
import the new managed DLL and call serialize on it.

Heres some pseudo code....
RuntimeMap* pMap = CreateRuntime(); // MFC objects hierarchy

// pMap->Serialize( ar ) // MFC serialization now replaced

// Having imported the new runtime .NET DLL....
RuntimeMap2^ pMap2 = gcnew RuntimeMap2();

pMap->Convert2DotNet( pMap2 ); // basically converts from MFC to
STL\CLR etc, setting properties on target objects

// created .NET binary formatter etc ....
formatter->Serialize( pMap2 );
Thanks for all your help so far guys, do you think the above makes
sense? please feel free to critique...

Nov 28 '05 #12
Herby wrote:
Ok, im changing my thinking from pesimistic to optimistic and this has
illuminated a solution.

My new runtime application will mostly use C++\CLI and STL\CLR and use
.NET specifics for things like serialization etc.
I will assume under .NET peformance will not suffer too much and it
will be accepted, thus removing the need to compile this to un-managed
for some clients( pessimistic view ). If the pessimistic view turns out
to be right then some parts of the system will have to have an
un-managed replacement, such as writing my own DIY serialisation using
SCL streams and .NET BinaryReader classes.

My design-time applicaton will then use mixed mode compilation and
import the new managed DLL and call serialize on it.

Heres some pseudo code....
RuntimeMap* pMap = CreateRuntime(); // MFC objects hierarchy

// pMap->Serialize( ar ) // MFC serialization now replaced

// Having imported the new runtime .NET DLL....
RuntimeMap2^ pMap2 = gcnew RuntimeMap2();

pMap->Convert2DotNet( pMap2 ); // basically converts from MFC to
STL\CLR etc, setting properties on target objects

// created .NET binary formatter etc ....
formatter->Serialize( pMap2 );
Thanks for all your help so far guys, do you think the above makes
sense? please feel free to critique...


It looks like the approach that will be the least work, so go for it.
The only hitch is the slight performance degradation from the
"unnecessary" call to Convert2DotNet, but that can't be that bad.
Anyway, almost certainly better than writing your own code, but make
sure that nothing is CLR version dependent (I don't know much about .NET
serialization, but Java's variant sometimes broke compatibility on some
classes between versions IIRC).

Tom
Nov 28 '05 #13
Cheers Tom, that makes me feel better.

The intermediate step Convert2DotNet is a necessary evil it would seem.
But kind of clean.
From a users perspective it should not be noticable.


Thanks.

Nov 28 '05 #14
Visibility problem:

I have something defined like the following

[Serializable]
public ref class FunctionArray : public vector<FunctionBase^>
Because of the need for the Convert2DotNet function, most of my classes
are going to need to be accessible from outside the assembly so that
their properties can be set.

Because of inheriting from vector which is not marked public, i get the
following error....

c:\dev.2005.net\runtime\runtime\FunctionArray.h(12 ) : error C3213: base
class 'cliext::vector<_Value_t>' is less accessible than
'FunctionArray'

Am i forced now to make vector a member of FunctionArray?
I cannot subclass from STL given that class is to be made public
outside its assembly?

Dec 1 '05 #15
Having moved the vector to become a private data member of
FunctionArray, i then get the following error when i attempt to
serialize this class

Failed to serialize. Reason: Type 'cliext.vector<FunctionBase ^>' in
Assembly 'Runtime2, Version=1.0.2161.21524, Culture=neutral,
PublicKeyToken=null' is not marked as serializable.

Are the STL\CLR containers to be made serializable, or must i implement
ISerializable for FunctionArray and do it myself for the objects it
contains?

Thanks in advance.

Dec 1 '05 #16

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

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
1
by: andrewcw | last post by:
There is an error in XML document (1, 2). I used XML spy to create the XML and XSD. When I asked to have the XML validated it said it was OK. I used the .net SDK to generate the class. I have...
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
3
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
4
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I...
5
by: Nikola Skoric | last post by:
I ran in Mono a program developed on .NET Framework 2.0 and it ran OK until I tried to desirialize a object. There the program died abruptly dumping this: System.ArgumentOutOfRangeException:...
0
by: bharathreddy | last post by:
Before going to that i want to say few thing on serialization : Serialization is the process of converting an object into a form that can be readily transported. For example, you can serialize an...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.