From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,TO_NO_BRKTS_PCNT autolearn=no autolearn_force=no version=3.4.5-pre1 Date: 16 Oct 91 16:18:51 GMT From: think.com!news.bbn.com!bbn.com!udo@ames.arc.nasa.gov (Udo Hollaender) Subject: Writing mess. with diff length in a file Message-ID: <66900@bbn.BBN.COM> List-Id: --------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.