comp.lang.ada
 help / color / mirror / Atom feed
* Automatic Serialization of Dynamic Structures in Ada
@ 2022-03-04 20:26 Manuel Gomez
  2022-03-04 22:01 ` Dmitry A. Kazakov
  0 siblings, 1 reply; 3+ messages in thread
From: Manuel Gomez @ 2022-03-04 20:26 UTC (permalink / raw)


I wanted to do automatic serialization of Ada types that make use of 
dynamic memory management with access types, but the standard solution 
only works for object values, not for access values. I've found a 
technical report describing a solution for that case, which apparently 
was implemented. Does anyone know if this tool is or were publicly 
available? Was an AI finally proposed as suggested in the Future Work?

https://core.ac.uk/download/pdf/147904594.pdf

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

* Re: Automatic Serialization of Dynamic Structures in Ada
  2022-03-04 20:26 Automatic Serialization of Dynamic Structures in Ada Manuel Gomez
@ 2022-03-04 22:01 ` Dmitry A. Kazakov
  2022-03-11  5:26   ` Matt Borchers
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitry A. Kazakov @ 2022-03-04 22:01 UTC (permalink / raw)


On 2022-03-04 21:26, Manuel Gomez wrote:
> I wanted to do automatic serialization of Ada types that make use of 
> dynamic memory management with access types,

That is impossible to do since the semantics of references access type 
implement is unknown. E.g. external references, references inside 
managed objects, references to non-movable, non-copyable objects, 
references created in certain order etc.

I am using a method where references are either explicitly manifested by 
the serialized objects or explicitly converted to offsets by objects 
containing them.

> but the standard solution 
> only works for object values, not for access values.

If you mean stream attributes remember that they are non-portable and 
have very limited use unless overridden.

> Was an AI finally proposed as suggested in the Future Work?

I doubt it could have practical use, e.g. for networking or persistence 
purposes.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

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

* Re: Automatic Serialization of Dynamic Structures in Ada
  2022-03-04 22:01 ` Dmitry A. Kazakov
@ 2022-03-11  5:26   ` Matt Borchers
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Borchers @ 2022-03-11  5:26 UTC (permalink / raw)


I'm not sure why Dmitry would say this is impossible unless you are actually talking about creating a generic package to serialize objects.  Objects to a generic routine would be a black box so you would have to supply the serialization routines to the generic at instantiation.  Otherwise, there are certainly cases that may prove impossible or challenging, but I think the OP is thinking of perhaps serializing simpler cases like a linked list, tree, or graph in memory.  In this case, it is definitely possible even if the objects in the structure contain other dynamic elements.

If you are serializing a structure where access type links are followed to do a simple traversal of the structure then you don't need distinct IDs for the objects that you are serializing.  Otherwise, you probably do in order to fully regenerate the dynamic structure.

My approach to this is to create a 'Read, 'Write, 'Input, and 'Output routines for both the access type and the type being accessed.  I do this mostly for completeness, but it's not necessary if the program doesn't need both.  You many not need a 'Read and 'Write, but if you need one then use 'Input and 'Output.  There is a difference that should be obeyed for proper serialization:  'Output writes any necessary bounds of an array or other container type before writing the data and 'Input expects that bounds information to be available before reading the data.  So, I generally have 'Output call 'Write and 'Input call 'Read to avoid duplication of code.

The 'Output on the access type writes a Boolean value before the access value itself - True if not null.  Then I write any boundary information necessary then invoke the 'Write on the .all of the access type.  For 'Input, it would obviously read the Boolean value and if True read the boundary data and create a new instance of the expected type and then call 'Read to load data into the newly created .all object.

For a linked list, tree, and even a complete graph a simple traversal works fine.  For an incomplete graph, you may want to write out the nodes first and then write out coded information for how the nodes are linked so a reconstruction is possible from the input stream.

This method even works for tagged types and the class-wide streaming routines that will rebuild the proper objects because the class-wide streaming routines stream the tag information about the object allowing dispatching on 'Class'Input (if I remember correctly).

Regards,
Matt

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

end of thread, other threads:[~2022-03-11  5:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04 20:26 Automatic Serialization of Dynamic Structures in Ada Manuel Gomez
2022-03-04 22:01 ` Dmitry A. Kazakov
2022-03-11  5:26   ` Matt Borchers

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