From: "markp" <markwork66@yahoo.com>
Subject: Memory Leak
Date: 3 Jan 2006 08:15:45 -0800
Date: 2006-01-03T08:15:45-08:00 [thread overview]
Message-ID: <1136304945.663764.14490@g14g2000cwa.googlegroups.com> (raw)
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;
next reply other threads:[~2006-01-03 16:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-03 16:15 markp [this message]
2006-01-03 18:06 ` Memory Leak Jeffrey R. Carter
2006-01-03 18:57 ` markp
2006-01-03 19:03 ` Martin Dowie
2006-01-03 19:05 ` markp
2006-01-04 4:46 ` Jeffrey R. Carter
2006-01-05 21:12 ` Ludovic Brenta
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox