From: think.com!news.bbn.com!bbn.com!udo@ames.arc.nasa.gov (Udo Hollaender)
Subject: Writing mess. with diff length in a file
Date: 16 Oct 91 16:18:51 GMT [thread overview]
Message-ID: <66900@bbn.BBN.COM> (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.
reply other threads:[~1991-10-16 16:18 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox