comp.lang.ada
 help / color / mirror / Atom feed
* S'Write and How To Count Bytes
@ 2000-09-30  0:00 Marin David Condic
  2000-10-01  0:00 ` David C. Hoos, Sr.
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: Marin David Condic @ 2000-09-30  0:00 UTC (permalink / raw)


Suppose I have a type something like this:

    type My_Record is record
        A_String    : Unbounded_String := Null_Unbounded_String ;
    end record ;

In theory, I should be able to create an object that is derived from
Ada.Streams.Root_Stream_Type which has a Read and Write procedure that
will allow me to create a call such as:

    My_Record'Write (Ptr, A_Record) ;

where Ptr is a pointer to my derived Root_Stream_Type object. Now here's
where it gets fun:

The object derived from Root_Stream_Type is going to contain some
version of a Stream_Element_Array. Possibly dynamically allocated. The
Write procedure that I create for the Root_Stream_Type is going to get
automagically called with a Stream_Element_Array parameter, from which
you could determine the size, allocate what you need for a buffer and
attach it to the Root_Stream_Type. That buffer can then be sent
somewhere or used in some other manner.

The problem is this: What if you want the record to contain the number
of bytes that it converts to so that the number ends up in the stream?
You can't easily determine how many bytes there will be in the record
nor can you determine what the 'Write is really going to produce. You
could possibly retain the size information in your Root_Stream_Type
after the conversion, but by then its too late. You already converted it
and if you had a "Count" field in the record, its value is probably dead
wrong. You could convert it to the stream once, interrogate the
Root_Stream_Type you built to determine the number of bytes in it, then
include that byte count in your record and convert it all over again.
That seems a little inefficient.

Is there any good way of determining in advance how many bytes you are
going to get when converting an object to a stream?

MDC
--
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

    "Giving money and power to Government is like giving whiskey
    and car keys to teenage boys."

        --   P. J. O'Rourke
======================================================================






^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: S'Write and How To Count Bytes
@ 2000-10-02  0:00 tmoran
  2000-10-03  5:21 ` Marin David Condic
  0 siblings, 1 reply; 29+ messages in thread
From: tmoran @ 2000-10-02  0:00 UTC (permalink / raw)


>... I will get out what I expect.
  type Temperature is new Integer range 60 .. 80;
  for Temperature'size use 8; -- or 7
Is a Temperature'Write going to produce one byte, because that's how
big Temperature is, or 4 bytes, because that's how big Integer is?
  type R is record
    Speed : Long_Integer;
  end record;
  for R use record
    S at 0 range 0 .. 7;
  end record;
Will an R'Write produce one byte for S, or 8 or what?

>A perfect solution would be controlled representation of the (tagged)
>record types and a fast overlay of a Stream_Element_Array.
  I remember this discussion, but not the bottom line.  What's wrong
with
  TAG_SIZE : constant := 4;
  ...
  type This_Buffer is new Buffer with record
    Speed : Integer;
    T : Temperature;
  end record;
  for This_Buffer use record
    Speed at TAG_SIZE range 0 .. 7;
    T at Tag_Size+1 range 0 .. 7;
  end record;
and then overlay a Stream_Element_Array?  (Or a
System.Storage_Elements.Storage_Array?)
  I'd rather trust to TAG_SIZE being 4, or at least a single thing to
change, as I move between compilers, rather than trusting Stream stuff.




^ permalink raw reply	[flat|nested] 29+ messages in thread
* Re: S'Write and How To Count Bytes
@ 2000-10-03  0:00 Mario Amado Alves
  2000-10-03  0:00 ` Marin David Condic
  0 siblings, 1 reply; 29+ messages in thread
From: Mario Amado Alves @ 2000-10-03  0:00 UTC (permalink / raw)
  To: comp.lang.ada

The "bottom line" was very simple: you may define the representation in
primary storage but not in secondary. This is what the ARM prescribes. I
also would like to see this changed in Ada20XX.

On Mon, 2 Oct 2000 tmoran@bix.com wrote:

> >... I will get out what I expect.
>   type Temperature is new Integer range 60 .. 80;
>   for Temperature'size use 8; -- or 7
> Is a Temperature'Write going to produce one byte, because that's how
> big Temperature is, or 4 bytes, because that's how big Integer is?
>   type R is record
>     Speed : Long_Integer;
>   end record;
>   for R use record
>     S at 0 range 0 .. 7;
>   end record;
> Will an R'Write produce one byte for S, or 8 or what?
> 
> >A perfect solution would be controlled representation of the (tagged)
> >record types and a fast overlay of a Stream_Element_Array.
>   I remember this discussion, but not the bottom line.  What's wrong
> with
>   TAG_SIZE : constant := 4;
>   ...
>   type This_Buffer is new Buffer with record
>     Speed : Integer;
>     T : Temperature;
>   end record;
>   for This_Buffer use record
>     Speed at TAG_SIZE range 0 .. 7;
>     T at Tag_Size+1 range 0 .. 7;
>   end record;
> and then overlay a Stream_Element_Array?  (Or a
> System.Storage_Elements.Storage_Array?)
>   I'd rather trust to TAG_SIZE being 4, or at least a single thing to
> change, as I move between compilers, rather than trusting Stream stuff.
> 

| |,| | | |RuaFranciscoTaborda24RcD 2815-249CharnecaCaparica 351+939354002
|M|A|R|I|O|
|A|M|A|D|O|DepartmentoDeInformaticaFCT/UNL 2825-114 Caparica 351+212958536
|A|L|V|E|S|                                                  fax 212948541
| | | | | |                 maa@di.fct.unl.pt                FCT 212948300






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

end of thread, other threads:[~2000-10-11  0:00 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-30  0:00 S'Write and How To Count Bytes Marin David Condic
2000-10-01  0:00 ` David C. Hoos, Sr.
2000-10-02  0:00   ` Marin David Condic
2000-10-02  0:00     ` Ted Dennison
2000-10-02  0:00       ` tmoran
2000-10-02  0:00         ` Marin David Condic
2000-10-02  0:00         ` tmoran
2000-10-02  0:00           ` Ted Dennison
2000-10-02  0:00           ` Marin David Condic
2000-10-11  0:00             ` Nick Roberts
2000-10-11  0:00               ` Marin David Condic
2000-10-03  0:00       ` Robert A Duff
2000-10-06  0:00         ` Randy Brukardt
2000-10-07  0:11           ` Ted Dennison
2000-10-06  0:00             ` Randy Brukardt
2000-10-07  0:00             ` Marin David Condic
2000-10-08  0:00               ` Jean-Pierre Rosen
2000-10-09  0:00                 ` Randy Brukardt
2000-10-11  0:00                 ` Marin David Condic
2000-10-02  0:00   ` Dr. Joachim Schr�er
2000-10-02  0:00     ` Marin David Condic
2000-10-06  0:00       ` Charles Hixson
2000-10-02  0:00 ` David C. Hoos, Sr.
2000-10-02  6:58 ` tmoran
2000-10-02  0:00   ` Marin David Condic
  -- strict thread matches above, loose matches on Subject: below --
2000-10-02  0:00 tmoran
2000-10-03  5:21 ` Marin David Condic
2000-10-03  0:00 Mario Amado Alves
2000-10-03  0:00 ` Marin David Condic

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