comp.lang.ada
 help / color / mirror / Atom feed
* Streams and Access types
@ 2003-01-29 14:09 Rodrigo García
  2003-01-29 19:51 ` Stephen Leake
  0 siblings, 1 reply; 5+ messages in thread
From: Rodrigo García @ 2003-01-29 14:09 UTC (permalink / raw)


Hello,

   As it happens with any elementary type, the serialization of access 
types is implementation defined (RM 13.13.2 (9)). However, that means 
that, when an access variable is serialized, it is the value of the 
access variable itself which is serialized, not the object pointed by 
the access variable.

   In GNAT this value is just a memory address. This is not very useful 
if we want to serialize, let's say, a linked list and then store it in 
the hard disk.

   One solution is to do custom serialization but, does anybody knows of 
an Ada compiler that can automatically serialize the objects pointed by 
access variables (recursively if needed, such in the case of the linked 
list)?

   Thanks

Rodrigo




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Streams and Access types
  2003-01-29 14:09 Streams and Access types Rodrigo García
@ 2003-01-29 19:51 ` Stephen Leake
  2003-01-30 20:41   ` Simon Wright
  0 siblings, 1 reply; 5+ messages in thread
From: Stephen Leake @ 2003-01-29 19:51 UTC (permalink / raw)


Rodrigo Garc�a <rodrigo.garcia@epfl.ch> writes:

>    One solution is to do custom serialization but, does anybody knows
> of an Ada compiler that can automatically serialize the objects
> pointed by access variables (recursively if needed, such in the case
> of the linked list)?

This is not possible in general. How would the compiler resolve a
circular list? All doubly-linked lists have circles, so it is a real
problem. 

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Streams and Access types
  2003-01-29 19:51 ` Stephen Leake
@ 2003-01-30 20:41   ` Simon Wright
  2003-01-30 21:56     ` James S. Rogers
  2003-01-31 11:13     ` Rodrigo Garcia
  0 siblings, 2 replies; 5+ messages in thread
From: Simon Wright @ 2003-01-30 20:41 UTC (permalink / raw)


Stephen Leake <Stephen.A.Leake@nasa.gov> writes:

> Rodrigo Garc�a <rodrigo.garcia@epfl.ch> writes:
> 
> >    One solution is to do custom serialization but, does anybody knows
> > of an Ada compiler that can automatically serialize the objects
> > pointed by access variables (recursively if needed, such in the case
> > of the linked list)?
> 
> This is not possible in general. How would the compiler resolve a
> circular list? All doubly-linked lists have circles, so it is a real
> problem. 

Clearly this can be done! Java does it (unless I'm mistaken). You have
to keep track of what's been serialized already, I suppose.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Streams and Access types
  2003-01-30 20:41   ` Simon Wright
@ 2003-01-30 21:56     ` James S. Rogers
  2003-01-31 11:13     ` Rodrigo Garcia
  1 sibling, 0 replies; 5+ messages in thread
From: James S. Rogers @ 2003-01-30 21:56 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

"Simon Wright" <simon@pushface.org> wrote in message
news:x7visw62wwu.fsf@smaug.pushface.org...
> Stephen Leake <Stephen.A.Leake@nasa.gov> writes:
>
> > Rodrigo Garc�a <rodrigo.garcia@epfl.ch> writes:
> >
> > >    One solution is to do custom serialization but, does anybody knows
> > > of an Ada compiler that can automatically serialize the objects
> > > pointed by access variables (recursively if needed, such in the case
> > > of the linked list)?
> >
> > This is not possible in general. How would the compiler resolve a
> > circular list? All doubly-linked lists have circles, so it is a real
> > problem.
>
> Clearly this can be done! Java does it (unless I'm mistaken). You have
> to keep track of what's been serialized already, I suppose.

Java serialization is actually a bit more complicated than you imply.
Only the classes that implement the Serializable interface may be
serialized. Java classes that need to control the serialization process
have several possible approaches.

The first approach is to override the readObject() and
writeObject() methods. These methods allow pre and post
processing to be done for the serialization process.

The second, and more powerful approach, is to implement
the Externalizable interface, which extends the Serializable
interface. All classes are tested by the serialization mechanism to
determine if they implement the Externalizable interface. This
interface declares two methods: readExternal() and
writeExternal(). These methods are often used to perform
encryption, or handle other algorithms, including writing data
in a special format.

Jim Rogers





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Streams and Access types
  2003-01-30 20:41   ` Simon Wright
  2003-01-30 21:56     ` James S. Rogers
@ 2003-01-31 11:13     ` Rodrigo Garcia
  1 sibling, 0 replies; 5+ messages in thread
From: Rodrigo Garcia @ 2003-01-31 11:13 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1322 bytes --]

"Simon Wright" <simon@pushface.org> wrote in message
news:x7visw62wwu.fsf@smaug.pushface.org...
> Stephen Leake <Stephen.A.Leake@nasa.gov> writes:
>
> > Rodrigo Garc�a <rodrigo.garcia@epfl.ch> writes:
> >
> > >    One solution is to do custom serialization but, does anybody knows
> > > of an Ada compiler that can automatically serialize the objects
> > > pointed by access variables (recursively if needed, such in the case
> > > of the linked list)?
> >
> > This is not possible in general. How would the compiler resolve a
> > circular list? All doubly-linked lists have circles, so it is a real
> > problem.
>
> Clearly this can be done! Java does it (unless I'm mistaken). You have
> to keep track of what's been serialized already, I suppose.

    You are right. Java does it by assigning a "handle" (a number starting
at 0x7E0000) that identifies each serialized object. If the object is
referenced again, Java serializes just its handle.

    There is a problem with this though. If the object is modified and sent
again through the same stream, it will be identified by its handle and this
will not reflect the modifications. You have to restart the stream in order
to serialize the object again.

    Anyway, I only wanted to know if there is already an Ada compiler that
does something similar.

Rodrigo





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-01-31 11:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-29 14:09 Streams and Access types Rodrigo García
2003-01-29 19:51 ` Stephen Leake
2003-01-30 20:41   ` Simon Wright
2003-01-30 21:56     ` James S. Rogers
2003-01-31 11:13     ` Rodrigo Garcia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox