ada 中的单个位数组?

问题描述 投票:0回答:1

如果我写了

type u1 is range 0 .. 1;
type Index is range 0 .. 499999;
type U1Array is array(Index) of u1;

我可以假设这将是一个位向量,它有效地打包单个 u1 实例吗? IE。 8 位/字节?

ada
1个回答
0
投票

最好先检查再假设。可以使用

-gnatR2
检查数据类型的表示(请参阅此处)。下面的快速检查表明该数组不是位向量。它的组件大小将为 8 位,总数组大小将为 4,000,000 [位]。要将其作为位向量,您需要将其设为“压缩”数组(请参阅RM 13.2)。打包数组的大小为 500,000 [位]。

foo.ads

package Foo is

   type u1 is range 0 .. 1;
   type Index is range 0 .. 499999;
   
   type U1Array is array(Index) of u1;
   type U1PackedArray is array(Index) of u1 with Pack;   

end Foo;

输出

$ gcc -c foo.ads -gnatR2

Representation information for unit Foo (spec)
----------------------------------------------

for U1'Object_Size use 8;
for U1'Value_Size use 1;
for U1'Alignment use 1;

for Index'Object_Size use 32;
for Index'Value_Size use 19;
for Index'Alignment use 4;

for U1array'Size use 4000000;
for U1array'Alignment use 1;
for U1array'Component_Size use 8;

for U1packedarray'Size use 500000;
for U1packedarray'Alignment use 1;
for U1packedarray'Component_Size use 1;
© www.soinside.com 2019 - 2024. All rights reserved.