From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,653642c0bd258f9f X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Received: by 10.224.27.14 with SMTP id g14mr7678623qac.1.1347380915042; Tue, 11 Sep 2012 09:28:35 -0700 (PDT) Received: by 10.52.66.235 with SMTP id i11mr1692855vdt.7.1347380914926; Tue, 11 Sep 2012 09:28:34 -0700 (PDT) Path: da15ni3445qab.0!nntp.google.com!v8no166017qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 11 Sep 2012 09:28:34 -0700 (PDT) In-Reply-To: <97ff13ad-308a-416f-a300-6c7d9da3d71b@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=46.195.129.38; posting-account=3_reEwoAAAC163IAIrx427KYmwahFuh9 NNTP-Posting-Host: 46.195.129.38 References: <97ff13ad-308a-416f-a300-6c7d9da3d71b@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: 'Size of an object From: =?ISO-8859-1?Q?bj=F6rn_lundin?= Injection-Date: Tue, 11 Sep 2012 16:28:35 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-09-11T09:28:34-07:00 List-Id: > -- thanks, Adam Den tisdagen den 11:e september 2012 kl. 17:52:03 UTC+2 skrev Adam Benescha= n: >In a larger procedure, > what might you use 'Size on a local variable for; if you wouldn't ever > use it on a local variable, then what kinds of *objects* (not types or > subtypes) might you apply 'Size to, and what would you do with the value? We have a system that depending on equipment at site, has somewhere between= 10 and 60 background processes, or daemons. depending on platform the ipc mechanism is different, shared mem +semaphors= , named pipes, and memory mapped files are the one we use for AIX, Linux and windows. This is on ppc and intel. but only 32 bit. but was on vax/alpha once as well All implemtations are based on sending a record of data as an array of byte= s, converted with unchecked_conversion.=20 when converting, and in message envelope, it is nice to have the size of th= e byte array. since it varies betwen different records. example spec: generic Identity : Identity_Type; type Data_Type is private; package Generic_io is procedure Send (Receiver : in Process_Type; Data : in Data_T= ype); function Unpack (Message : in Message_Type) return Data_Type; function Pack (Data : in Data_Type) return Message_Type; end Generic_io; ----------------------------------------------------------------- a body looks like Note the use of Data_Length in the body, which comes from Data_Type'Size/Sy= stem.Storage_Unit package body Generic_io is Data_Length : constant Natural :=3D Natural (Data_Type'Size/System.S= torage_Unit); subtype Byte_Array_Message is Byte_Array (1..Data_Length); subtype Byte_Array_2 is Byte_Array (1..2); ---------------------------------------------------- function Pack (Data : in Data_Type) return Message_Type is function Data_To_Byte_Array is new Unchecked_Conversion (Data_Type, Byte_Array_Message); Message : Message_Type; begin if (Data'Size > (MAX_DATA_LENGHT * System.Storage_unit)) then Log ("Message size is: " & Natural'Image(Data'size/System.Storage_U= nit), Always); Log("MAX_DATA_LENGHT is: " & Positive'Image(MAX_DATA_LENGHT), Alway= s); raise Too_Big_Message; end if; Message.Message_Head.Identity :=3D Identity; Message.Message_Body.Data (1..Integer (Data_Length)) :=3D Data_To_Byt= e_Array(Data); Message.Message_Body.Data_Length :=3D Data_Length; return Message; end Pack; ---------------------------------------------------- function Unpack (Message : Message_Type) return Data_Type is function Message_To_Data is new Unchecked_Conversion(Byte_Array_Messa= ge, Data_Type); begin return Message_To_Data (Message.Message_Body.Data (1..Data_Length)); end Unpack; ..... end Generic_io; typical client usage is=20 package tst is type bnl is record a : integer :=3D 10; b : String(1..3) :=3D "Hej"; c : String(1..1017) :=3D (others =3D> '-'); end record; end tst; --sending package bnl2_Package is new Generic_io (Identity =3D> 3000, Data_Type =3D> tst.bnl); rec : tst.bnl; m: message_type; rec.a :=3D rec.a + 1; -- send to 'p2' bnl2_Package.send(("p2 ",(others =3D> ' ')),rec); -- --receiving receive(m); rec :=3D bnl2_Package.unpack(m); text_io.put_line ("a'Img b c'Img' " & rec.a'Img & rec.b & rec.c'Img);--= & rec.d); ----- This does not compile, I took the interesting bits only. -- Bj=F6rn