comp.lang.ada
 help / color / mirror / Atom feed
* Writing mess. with diff length in a file
@ 1991-10-16 16:18 Udo Hollaender
  0 siblings, 0 replies; only message in thread
From: Udo Hollaender @ 1991-10-16 16:18 UTC (permalink / raw)


--------Posted for a friend---------------------------------------------

The task is greping messages and write them as fast as possible in a file.

(SunOS 4.1.1; Telegen 1.4A; File System Block size 8 kB).

The problem is to write messages with different lengths (e.g. from 64 to
1500 Bytes) in a file without wasting performance or disk space.


I tried three different methods:

* I defined a record lenght
My first attempt was to define the record length of my file 1500 Bytes long, an
d
to wrote for every message 1500 Bytes to my file, even if
the real network package was only 64 Bytes long.
But what a waste of diskspace!

My second idea was to convert (with unchecked_conversion) the messages
to an array of 16 Bits integer pieces. Then I filled up every record
of my file (witch is also defined as an array of 16 Bits integer pieces),
with this 16 Bits integer pieces. For example like this.

        File_record(100..164) := Converted_messages(1..64);

This method works fine. But the copy from Converted_messages to
File_record, and the write to my file, does me cost 50 % of my
IO-performance.

My third idea was to define a discriminant record type like this.

        type possible_messages is (Default, Information, Movement, Gunnery);

        type Message_type(what_type : possible_messages := Default) is record
          case  what_type is
            when Default =>
                Default_len      : integer; -- 4 Bytes long
                Default_data     : Default_data_type; -- 100 Bytes long
            when Information =>
                Information_len  : integer;
                Information_data : Information_data_type; -- 200 Bytes long
            when Movement =>
                Movement_len     : integer;
                Movement_data    : Movement_data_type; -- 300 Bytes long
            when Gunnery =>
                Gunnery_len      : integer;
                Gunnery_data     : Gunnery_data_type; -- 400 Bytes long
          end case;
        end record;

        Pack1 : Message_type(Default);
        Pack2 : Message_type(Information);
        Pack3 : Message_type(Movement);
        Pack4 : Message_type(Gunnery);

But if I write e.g. Pack1 into a file, my program writes 404 Bytes,
instead of 104 Bytes. The Compiler allocates the space of the
longest possible discriminant (Message_type(Gunnery)), and is always
writing this 404 Bytes in my file. So there is no difference to my
first idea.


So, how can I write messages with different lengths into a file
without wasting diskspace or IO-performance?

Much oblige

----------------------------------------------------------------------------
Schleifring & Apparatebau                       Franz Lammich
Am Hardtanger 10                                Phone: 08141 / 40356
8080 Fuerstenfeldbruck                          FAX:   08141 / 40345
Germany						
----------------------------------------------------------------------------

Please respond to uholl@bbn.com, I'll forward it to Franz.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1991-10-16 16:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1991-10-16 16:18 Writing mess. with diff length in a file Udo Hollaender

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