comp.lang.ada
 help / color / mirror / Atom feed
* Boolean array representation question
@ 1997-11-20  0:00 Jerry van Dijk
  1997-11-20  0:00 ` Matthew Heaney
  1997-11-21  0:00 ` John P. Lippiello
  0 siblings, 2 replies; 10+ messages in thread
From: Jerry van Dijk @ 1997-11-20  0:00 UTC (permalink / raw)



When compiling the following program:

   with Ada.Text_IO; use Ada.Text_IO;

   procedure Test_1 is
      type Bit_Array is array (Natural range <>) of Boolean;
      My_Array : Bit_Array (0 .. 4) := (others => False);
   begin
      Put_Line ("The size of Bit_Array is" &
        Integer'Image (My_Array'Size));
   end Test_1;

both GNAT and OA on NT report the size as 40 so I wonder if
this is some kind of magic number and where it is coming from.
Thanks,
Jerry.

--

-- Jerry van Dijk | Leiden, Holland
-- Consultant     | Team Ada
-- Ordina Finance | jdijk@acm.org




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

* Re: Boolean array representation question
  1997-11-20  0:00 Boolean array representation question Jerry van Dijk
@ 1997-11-20  0:00 ` Matthew Heaney
  1997-11-21  0:00 ` John P. Lippiello
  1 sibling, 0 replies; 10+ messages in thread
From: Matthew Heaney @ 1997-11-20  0:00 UTC (permalink / raw)



In article <880041511.80snx@jvdsys.nextjk.stuyts.nl>,
jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) wrote:

>When compiling the following program:
>
>   with Ada.Text_IO; use Ada.Text_IO;
>
>   procedure Test_1 is
>      type Bit_Array is array (Natural range <>) of Boolean;
>      My_Array : Bit_Array (0 .. 4) := (others => False);
>   begin
>      Put_Line ("The size of Bit_Array is" &
>        Integer'Image (My_Array'Size));
>   end Test_1;
>
>both GNAT and OA on NT report the size as 40 so I wonder if
>this is some kind of magic number and where it is coming from.

The component size of Bit_Array is 8 bits, and there are 5 components in
the array object.  That makes 5 x 8 = 40 bits.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Boolean array representation question
  1997-11-20  0:00 Boolean array representation question Jerry van Dijk
  1997-11-20  0:00 ` Matthew Heaney
@ 1997-11-21  0:00 ` John P. Lippiello
  1997-11-22  0:00   ` Jerry van Dijk
  1 sibling, 1 reply; 10+ messages in thread
From: John P. Lippiello @ 1997-11-21  0:00 UTC (permalink / raw)



The size 40 is to be expected since you have an array of 5 booleans and each
boolean takes 8 bits.  In order to get the size down to 8 bits, try the
following line:

with Ada.Text_IO; use Ada.Text_IO;
procedure Test_1 is
   type Bit_Array is array (Natural range <>) of Boolean;
   pragma pack(Bit_Array); -- ADD THIS LINE
   My_Array : Bit_Array (0 .. 4) := (others => False);
begin
   Put_Line ("The size of Bit_Array is" &
   Integer'Image (My_Array'Size));
end Test_1;


Jerry van Dijk wrote in message <880041511.80snx@jvdsys.nextjk.stuyts.nl>...
>When compiling the following program:
>
>   with Ada.Text_IO; use Ada.Text_IO;
>
>   procedure Test_1 is
>      type Bit_Array is array (Natural range <>) of Boolean;
>      My_Array : Bit_Array (0 .. 4) := (others => False);
>   begin
>      Put_Line ("The size of Bit_Array is" &
>        Integer'Image (My_Array'Size));
>   end Test_1;
>
>both GNAT and OA on NT report the size as 40 so I wonder if
>this is some kind of magic number and where it is coming from.
>Thanks,
>Jerry.
>
>--
>
>-- Jerry van Dijk | Leiden, Holland
>-- Consultant     | Team Ada
>-- Ordina Finance | jdijk@acm.org






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

* Re: Boolean array representation question
  1997-11-21  0:00 ` John P. Lippiello
@ 1997-11-22  0:00   ` Jerry van Dijk
  1997-11-22  0:00     ` Robert Dewar
  1997-11-22  0:00     ` Matthew Heaney
  0 siblings, 2 replies; 10+ messages in thread
From: Jerry van Dijk @ 1997-11-22  0:00 UTC (permalink / raw)



In article <EK033F.9ps@sd.aonix.com> lippiell@ma.aonix.com writes:

>   pragma pack(Bit_Array); -- ADD THIS LINE

Yes, I know.

The point is for some reason I have Boolean'Size = 1 in my
head and cannot find the Boolean'Size =8^HStorage_Unit, other
implicitly in 3.5.3.

--

-- Jerry van Dijk | Leiden, Holland
-- Consultant     | Team Ada
-- Ordina Finance | jdijk@acm.org




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

* Re: Boolean array representation question
  1997-11-22  0:00   ` Jerry van Dijk
  1997-11-22  0:00     ` Robert Dewar
@ 1997-11-22  0:00     ` Matthew Heaney
  1997-11-22  0:00       ` Robert Dewar
  1997-11-23  0:00       ` Geert Bosch
  1 sibling, 2 replies; 10+ messages in thread
From: Matthew Heaney @ 1997-11-22  0:00 UTC (permalink / raw)



In article <880170219.81snx@jvdsys.nextjk.stuyts.nl>,
jerry@jvdsys.nextjk.stuyts.nl (Jerry van Dijk) wrote:

>In article <EK033F.9ps@sd.aonix.com> lippiell@ma.aonix.com writes:
>
>>   pragma pack(Bit_Array); -- ADD THIS LINE
>
>Yes, I know.
>
>The point is for some reason I have Boolean'Size = 1 in my
>head and cannot find the Boolean'Size =8^HStorage_Unit, other
>implicitly in 3.5.3.

You've got it right; Boolean'Size is defined to be 1.  However, you're
really interested in the component size of the array object.  The only
requirement is that the size of the array component can't be less than the
size of the component type.

If your compiler optimizes for speed, it's going to use the most
time-efficient way to get the value of a component.  For a Boolean, it
makes the most sense to allocate some integral number of storage elements
for each component.  It could be 8, 16, 32, whatever.  The value 8 seems to
be the best compromise between time and space.

To pack the components in contiguous bits by default would mean that it
takes a lot longer to access each component (on an architecture in which
each bit isn't independently addressable).

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: Boolean array representation question
  1997-11-22  0:00     ` Matthew Heaney
@ 1997-11-22  0:00       ` Robert Dewar
  1997-11-23  0:00       ` Geert Bosch
  1 sibling, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1997-11-22  0:00 UTC (permalink / raw)



Matthew says

<<If your compiler optimizes for speed, it's going to use the most
time-efficient way to get the value of a component.  For a Boolean, it
makes the most sense to allocate some integral number of storage elements
for each component.  It could be 8, 16, 32, whatever.  The value 8 seems to
be the best compromise between time and space.>>

No, this misses the point. On almost all architectures, the reason for
choosing a component size of 8 is driven by semantic requirements for
independence. FOr a full discussion of the independence issue for
shared variables, see Norman Schulman's thesis on shared variables
(Robert Dewar advisor, NYU, about ten years ago), or for a summary,
read my Ada 9X paper on shared variables.





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

* Re: Boolean array representation question
  1997-11-22  0:00   ` Jerry van Dijk
@ 1997-11-22  0:00     ` Robert Dewar
  1997-11-22  0:00     ` Matthew Heaney
  1 sibling, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1997-11-22  0:00 UTC (permalink / raw)



jerry says

<<The point is for some reason I have Boolean'Size = 1 in my
head and cannot find the Boolean'Size =8^HStorage_Unit, other
implicitly in 3.5.3.>>


Boolean'Size is indeed 1, but if you think that means that all Boolean
objects are of size one bit, you are not reading the RM carefully enough.

This rep clause stuff is tricky. In practice we find that a lot of the
problems in porting code are because of lack of understanding of these
issues, and a lot of our support work involves explaining the issues in
specific situations, and working out how to deal with them in the
Ada 95 and GNAT contexts.






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

* Re: Boolean array representation question
  1997-11-22  0:00     ` Matthew Heaney
  1997-11-22  0:00       ` Robert Dewar
@ 1997-11-23  0:00       ` Geert Bosch
  1997-11-24  0:00         ` Larry Kilgallen
  1 sibling, 1 reply; 10+ messages in thread
From: Geert Bosch @ 1997-11-23  0:00 UTC (permalink / raw)



Matthew Heaney <mheaney@ni.net> wrote:

   To pack the components in contiguous bits by default would mean that it
   takes a lot longer to access each component (on an architecture in which
   each bit isn't independently addressable).

This still misses the point, I'm afraid. Components of an array
(unpacked) must be independently addressable, so different elements
of the same array can be concurrently accessed without one task
affecting the other.

Regards,
   Geert




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

* Re: Boolean array representation question
  1997-11-24  0:00         ` Larry Kilgallen
@ 1997-11-24  0:00           ` Robert Dewar
  0 siblings, 0 replies; 10+ messages in thread
From: Robert Dewar @ 1997-11-24  0:00 UTC (permalink / raw)



Larry says

<<> This still misses the point, I'm afraid. Components of an array
> (unpacked) must be independently addressable, so different elements
> of the same array can be concurrently accessed without one task
> affecting the other.

So which is it, independently addressable or independently accessible ?
On an Alpha 21064 these are different values - 8 bits vs 32 bits.

Larry Kilgallen
>>


For most people these terms are identical, but there is no point in 
arguing over terminology. Independent here means that separate tasks can
read and write separate elements without intefering with one another. Note
that this means that on the (old) Alpha, a character in a non-packed record
by default takes 32 bits.





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

* Re: Boolean array representation question
  1997-11-23  0:00       ` Geert Bosch
@ 1997-11-24  0:00         ` Larry Kilgallen
  1997-11-24  0:00           ` Robert Dewar
  0 siblings, 1 reply; 10+ messages in thread
From: Larry Kilgallen @ 1997-11-24  0:00 UTC (permalink / raw)



In article <6580q9$4p1$1@gonzo.sun3.iaf.nl>, Geert Bosch <geert@gonzo.sun3.iaf.nl> writes:

> This still misses the point, I'm afraid. Components of an array
> (unpacked) must be independently addressable, so different elements
> of the same array can be concurrently accessed without one task
> affecting the other.

So which is it, independently addressable or independently accessible ?
On an Alpha 21064 these are different values - 8 bits vs 32 bits.

Larry Kilgallen




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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-20  0:00 Boolean array representation question Jerry van Dijk
1997-11-20  0:00 ` Matthew Heaney
1997-11-21  0:00 ` John P. Lippiello
1997-11-22  0:00   ` Jerry van Dijk
1997-11-22  0:00     ` Robert Dewar
1997-11-22  0:00     ` Matthew Heaney
1997-11-22  0:00       ` Robert Dewar
1997-11-23  0:00       ` Geert Bosch
1997-11-24  0:00         ` Larry Kilgallen
1997-11-24  0:00           ` Robert Dewar

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