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=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,32ab3f0888d7e4b2,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!g14g2000cwa.googlegroups.com!not-for-mail From: "markp" Newsgroups: comp.lang.ada Subject: Memory Leak Date: 3 Jan 2006 08:15:45 -0800 Organization: http://groups.google.com Message-ID: <1136304945.663764.14490@g14g2000cwa.googlegroups.com> NNTP-Posting-Host: 157.127.124.134 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1136304950 23562 127.0.0.1 (3 Jan 2006 16:15:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 3 Jan 2006 16:15:50 +0000 (UTC) User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; H010818; .NET CLR 1.1.4322),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: g14g2000cwa.googlegroups.com; posting-host=157.127.124.134; posting-account=_Inhcg0AAAAPC2BsuUqoGG-atarvM4_J Xref: g2news1.google.com comp.lang.ada:2431 Date: 2006-01-03T08:15:45-08:00 List-Id: We are experiencing a memory leak in out GNAT Ada program that we cannot explain. We've narrowed it down to our generic queue package as the culprit. However, all the memory in the package is allocated at instantiation. I've attached the source code and if anybody can see something, it would be greatly appreciated! The data types passed in during the instantiation are variant records. Lastly, does GNAT provide any queuing sevices? Thank you. generic ------------------------------------------------------------------------- -- -- Generic Formal Parameters -- ------------------------------------------------------------------------- -- The data type for the Message Queue type Data_Type is private; -- The number of entries in the Message Queue Message_Queue_Depth : in Integer; Queue_Name : string; package Generic_Message_Queues is ----------------------------------------------------------------------- -- -- Type Definitions -- ----------------------------------------------------------------------- -- Specifies the Priority Urgency of a message when -- a message is put into a Message Queue. type Priority_Urgency_Type is (Normal, Urgent); -- Indeces into both a high and low priority queue type Item_Count is new integer range 0 .. Message_Queue_Depth; type Item_Index is new integer range 1 .. Message_Queue_Depth; type Item_Array is array (Item_Index) of Data_Type; type Priority_Item_Count is new integer range 0 .. 10; type Priority_Item_Index is new integer range 1 .. 10; type Priority_Item_Array is array (Priority_Item_Index) of Data_Type; protected type Queue_Type is -- put a data element into the buffer entry Send(Elem : in Data_Type); -- put a data element into the High Priority Queue entry High_Priority_Send(Elem : in Data_Type); -- retrieve a data element from the buffer entry Receive(Elem: out Data_Type); -- return Count of number of items function Count return Integer; -- Clear queue procedure Flush; private Queue_Count : Item_Count := 0; Out_Index : Item_Index := 1; In_Index : Item_Index := 1; Data : Item_Array; Priority_Queue_Count : Priority_Item_Count := 0; Priority_Out_Index : Priority_Item_Index := 1; Priority_In_Index : Priority_Item_Index := 1; Priority_Data : Priority_Item_Array; end Queue_Type; -- Clear queue procedure Flush; -- put a data element into the buffer procedure Put( Data : in Data_Type; Priority_Urgency : in Priority_Urgency_Type := Normal); -- retrieve a data element from the buffer procedure Get( Data : out Data_Type); -- return Count of number of items function Count return Integer; end Generic_Message_Queues; package body Generic_Message_Queues is protected body Queue_Type is -- put a data element into the buffer entry Send(Elem: in Data_Type) when integer(Queue_Count) < Message_Queue_Depth is -- block until there is room in the Queue begin Data(In_Index) := Elem; In_Index := In_Index mod Item_Index(Message_Queue_Depth) + 1; Queue_Count := Queue_Count + 1; end Send; -- put a data element into the High Priority Queue entry High_Priority_Send(Elem: Data_Type) when integer(Priority_Queue_Count) < 10 is -- block until there is room in the Queue begin Priority_Data(Priority_In_Index) := Elem; Priority_In_Index := Priority_In_Index mod 10 + 1; Priority_Queue_Count := Priority_Queue_Count + 1; end High_Priority_Send; -- retrieve a data element from the buffer entry Receive(Elem: out Data_Type) when Queue_Count > 0 or else Priority_Queue_Count > 0 is -- block until there is something in the Queue begin if Priority_Queue_Count > 0 then Elem := Priority_Data(Priority_Out_Index); Priority_Out_Index := Priority_Out_Index mod 10 + 1; Priority_Queue_Count := Priority_Queue_Count - 1; else Elem := Data(Out_Index); Out_Index := Out_Index mod Item_Index(Message_Queue_Depth) + 1; Queue_Count := Queue_Count - 1; end if; end Receive; -- Clear queue procedure Flush is begin Queue_Count := 0; Out_Index := 1; In_Index := 1; Priority_Queue_Count := 0; Priority_Out_Index := 1; Priority_In_Index := 1; end Flush; -- return Count of number of items function Count return Integer is begin return(integer(Queue_Count)); end Count; end Queue_Type; Queue : Queue_Type; -- Clear queue procedure Flush is begin Queue.Flush; end Flush; -- put a data element into the buffer procedure Put( Data : in Data_Type; Priority_Urgency : in Priority_Urgency_Type := Normal) is begin if Priority_Urgency = Urgent then Queue.High_Priority_Send( Elem => Data); else Queue.Send( Elem => Data); end if; end Put; -- retrieve a data element from the buffer procedure Get( Data : out Data_Type) is begin Queue.Receive(Elem => Data); end Get; -- return Count of number of items function Count return Integer is begin Return(Queue.Count); end Count; end Generic_Message_Queues;