Ada -- 无约束对象队列数组导致 Storage_Error -- 如何解决?
Ada -- Array of queues of unconstrained objects results in Storage_Error -- How to resolve?
所以,免责声明,我现在才使用 Ada 几个星期......我希望有一个菜鸟错误导致这个。
所以我的(匿名)代码...
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Bounded_Synchronized_Queues;
procedure Hello is
type ID_Type is ( Invalid_Id,
Config_Id);
for ID_Type use ( Invalid_Id => 16#00#,
Config_Id => 16#11# );
for ID_Type'Size use 8;
type Config_Type is
record
data : Integer;
end record;
type Data_Type (i : ID_Type := Invalid_Id) is
record
Id : ID_Type := i;
case i is
when Invalid_Id => null;
when Config_Id => config : Config_Type;
when others => null;
end case;
end record with Unchecked_Union, Convention => C;
package Queue_Interface is
new Ada.Containers.Synchronized_Queue_Interfaces(Data_Type);
package Data_Queue is
new Ada.Containers.Bounded_Synchronized_Queues
( Queue_Interfaces => Queue_Interface,
Default_Capacity => 1);
Queue_Array : array(1..1) of Data_Queue.Queue;
begin
Put_Line("Queue_Array(1)'Size = " & Integer'Image(Queue_Array(1)'Size));
end Hello;
在线编译器(GNAT 7.1.1)上触发:raised STORAGE_ERROR : s-intman.adb:136 explicit raise
预期用途是与从串行端口提取数据的 C 级驱动程序交互。 (因此 unchecked_union 和其他表示条款)
假设无限期问题来自 Unconstrained 类型,已尝试使用 Indefinite_Holder 包装...但遇到了同样的错误。以为我不需要它,因为虽然它是一个不受约束的变体,但它的大小是确定的。不管怎样都是一样的。
还值得注意的是:
test1 : 数组 (ID_Type) Data_Type; -- 作品
测试 2:Data_Queue.Queue; -- 作品
test3:数组(1 .. 2)Data_Queue.Queue; -- Storage_Error
我做错了什么?
Bounded_Synchronized_Queue的定义是
protected type Queue
(Capacity : Count_Type := Default_Capacity;
Ceiling : System.Any_Priority := Default_Ceiling)
with Priority => Ceiling is
new Queue_Interfaces.Queue
看起来 GNAT 正在尝试为数组大小的所有潜在排列分配大小,从而导致一个非常大的类型。由于这是一个有限的类型,我不确定它是否仍然必须这样做(所以可能是一个错误)。
您可以通过更改声明的 discriminant to have a specific constraint:
来修复它
-- create an array of queues
Queue_Array : array(ID_Type) of ID_Holder_Queue.Queue
(Capacity => 16,
Ceiling => System.Priority'Last);
并使用系统;
这应该可以消除您的存储错误。 This 如果您使用的是 GNAT 编译器,则可能相关。
所以,免责声明,我现在才使用 Ada 几个星期......我希望有一个菜鸟错误导致这个。
所以我的(匿名)代码...
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Containers.Synchronized_Queue_Interfaces;
with Ada.Containers.Bounded_Synchronized_Queues;
procedure Hello is
type ID_Type is ( Invalid_Id,
Config_Id);
for ID_Type use ( Invalid_Id => 16#00#,
Config_Id => 16#11# );
for ID_Type'Size use 8;
type Config_Type is
record
data : Integer;
end record;
type Data_Type (i : ID_Type := Invalid_Id) is
record
Id : ID_Type := i;
case i is
when Invalid_Id => null;
when Config_Id => config : Config_Type;
when others => null;
end case;
end record with Unchecked_Union, Convention => C;
package Queue_Interface is
new Ada.Containers.Synchronized_Queue_Interfaces(Data_Type);
package Data_Queue is
new Ada.Containers.Bounded_Synchronized_Queues
( Queue_Interfaces => Queue_Interface,
Default_Capacity => 1);
Queue_Array : array(1..1) of Data_Queue.Queue;
begin
Put_Line("Queue_Array(1)'Size = " & Integer'Image(Queue_Array(1)'Size));
end Hello;
在线编译器(GNAT 7.1.1)上触发:raised STORAGE_ERROR : s-intman.adb:136 explicit raise
预期用途是与从串行端口提取数据的 C 级驱动程序交互。 (因此 unchecked_union 和其他表示条款)
假设无限期问题来自 Unconstrained 类型,已尝试使用 Indefinite_Holder 包装...但遇到了同样的错误。以为我不需要它,因为虽然它是一个不受约束的变体,但它的大小是确定的。不管怎样都是一样的。
还值得注意的是: test1 : 数组 (ID_Type) Data_Type; -- 作品 测试 2:Data_Queue.Queue; -- 作品 test3:数组(1 .. 2)Data_Queue.Queue; -- Storage_Error
我做错了什么?
Bounded_Synchronized_Queue的定义是
protected type Queue
(Capacity : Count_Type := Default_Capacity;
Ceiling : System.Any_Priority := Default_Ceiling)
with Priority => Ceiling is
new Queue_Interfaces.Queue
看起来 GNAT 正在尝试为数组大小的所有潜在排列分配大小,从而导致一个非常大的类型。由于这是一个有限的类型,我不确定它是否仍然必须这样做(所以可能是一个错误)。
您可以通过更改声明的 discriminant to have a specific constraint:
来修复它-- create an array of queues
Queue_Array : array(ID_Type) of ID_Holder_Queue.Queue
(Capacity => 16,
Ceiling => System.Priority'Last);
并使用系统;
这应该可以消除您的存储错误。 This 如果您使用的是 GNAT 编译器,则可能相关。