Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Loop in procedure not complete

Reply
Thread Tools

Loop in procedure not complete

 
 
ALuPin@web.de
Guest
Posts: n/a
 
      05-18-2005
Hi,

I am trying to monitor the loop index within a procedure in a VHDL
testbench as follows:



procedure test (signal Clock : std_logic;
Times : integer;
signal Data : std_logic_vector(7 downto 0) ) is

variable wait_index : integer;
variable i : integer;
variable j_help : integer;
variable ln : line;
begin

wait_index := Times;

LOOP1_OUT : for i in 0 to 15000 loop
j_help := i;

if (i <= wait_index) then
if i=wait_index then
writeline(OUTPUT,ln);
write(ln,string'("loop "));
write(ln,j_help);
end if;
wait on Clock, Data;
exit LOOP1_OUT when Data="10000100";
end if;

end loop;

end test;

-- Calling procedure within main process
process
begin
test(t_Clock, 50, t_Data);

wait;
end process;

I get no monitoring in Modelsim at all. Why?
("Data" remains "00000000" all the time so that no
loop exit comes into question)

When I comment the inner if-statement out
if (i <= wait_index) then
--if i=wait_index then
writeline(OUTPUT,ln);
write(ln,string'("loop "));
write(ln,j_help);
--end if;
wait on Clock, Data;
exit LOOP1_OUT when Data="10000100";
end if;

I get monitored in Modelsim
loop 0
loop 1
....
loop 49

But loop 50 is missing. Why?

Changings to
writeline(OUTPUT,ln);
write(ln,string'("loop "));
write(ln,i);
do not change anything.

Thank you for your help.

Rgds
André

 
Reply With Quote
 
 
 
 
Jonathan Bromley
Guest
Posts: n/a
 
      05-18-2005
On 18 May 2005 06:33:10 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:


>When I comment the inner if-statement out
>if (i <= wait_index) then
> --if i=wait_index then
> writeline(OUTPUT,ln);
> write(ln,string'("loop "));
> write(ln,j_help);
> --end if;
> wait on Clock, Data;
> exit LOOP1_OUT when Data="10000100";
>end if;
>
>I get monitored in Modelsim
>loop 0
>loop 1
>...
>loop 49
>
>But loop 50 is missing. Why?


Try moving the writeline() call to AFTER the two
write() calls, so that your message from the final
iteration is indeed written to stdout

And for further credit: explain why your original
code exhibits a memory leak.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:(E-Mail Removed)
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Reply With Quote
 
 
 
 
ALuPin@web.de
Guest
Posts: n/a
 
      05-18-2005
I have found some post on the topic "writeline VHDL"

>Write and Writeline are fuctions defined in the STD.TEXTIO >library of

VHDL.

> Line is a type def. It is access STRING. i.e it is a pointer
> to a STRING.



> Fn. Write adds the string specfd. to this Line (in Ur case strbuf).



> Writeline Flushes this line onto the file specfd. (in Ur case
>output).

\/
And from this the memory leak arises! Is that correct ?

 
Reply With Quote
 
Jonathan Bromley
Guest
Posts: n/a
 
      05-18-2005
On 18 May 2005 09:08:46 -0700, (E-Mail Removed) wrote:


>>Write and Writeline are fuctions defined in the STD.TEXTIO

>library of VHDL.
>
>> Line is a type def. It is access STRING. i.e it is a pointer
>> to a STRING.
>> Fn. Write adds the string specfd. to this Line (in Ur case strbuf).
>> Writeline Flushes this line onto the file specfd. (in Ur case
>>output).

>\/
>And from this the memory leak arises! Is that correct ?


Not quite.

Typically, a procedure that does text output will build up some
text in a LINE variable using WRITE() and then send it to a
file or the console using WRITELINE(). Each call to
WRITE(L, stuff)
allocates a little more memory, to accommodate the new text.
However, when you eventually do
WRITELINE(output, L)
the memory pointed-to by L is deallocated (returned to free store)
and L is reset to NULL. This is fine. There is no memory leak.

However, in your original code, you did some WRITE operations
without a final WRITELINE. Consequently, at the end of your
procedure, the line variable points to some memory that has been
allocated to your program. But then your procedure returns, the
line variable goes out of scope, and nothing points to the
memory any more! So the allocated memory is lost. Each time you
call the procedure, a little more memory is lost. There is a
memory leak.

Languages such as 'e' that do automatic garbage collection do
not suffer this problem, but of course they pay a price in
performance.

The correct solution is to be very sure that any local pointer
variables used in your procedure are deallocated before the
procedure returns. A procedure such as WRITELINE does the
deallocation automatically, but in some situations you must
do it for yourself.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:(E-Mail Removed)
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Reply With Quote
 
john Doef
Guest
Posts: n/a
 
      05-20-2005
Jonathan Bromley a écrit :
> On 18 May 2005 09:08:46 -0700, (E-Mail Removed) wrote:
>
>
> >>Write and Writeline are fuctions defined in the STD.TEXTIO

> >library of VHDL.
> >
> >> Line is a type def. It is access STRING. i.e it is a pointer
> >> to a STRING.
> >> Fn. Write adds the string specfd. to this Line (in Ur case

strbuf).
> >> Writeline Flushes this line onto the file specfd. (in Ur case
> >>output).

> >\/
> >And from this the memory leak arises! Is that correct ?

>
> Not quite.
>
> Typically, a procedure that does text output will build up some
> text in a LINE variable using WRITE() and then send it to a
> file or the console using WRITELINE(). Each call to
> WRITE(L, stuff)
> allocates a little more memory, to accommodate the new text.
> However, when you eventually do
> WRITELINE(output, L)
> the memory pointed-to by L is deallocated (returned to free store)
> and L is reset to NULL. This is fine. There is no memory leak.

Huu, this is not what the LRM says.

LRM says:
Procedure WRITELINE causes the current line designated by parameter L
to be written to the file and returns with the value of parameter L
designating a null string.

If L designates a null string, it is not reset to NULL.

JD.

 
Reply With Quote
 
Jonathan Bromley
Guest
Posts: n/a
 
      05-20-2005
On 20 May 2005 02:53:29 -0700, "john Doef" <(E-Mail Removed)>
wrote:

>Jonathan Bromley a écrit :

[...]
>> However, when you eventually do
>> WRITELINE(output, L)
>> the memory pointed-to by L is deallocated (returned to free store)
>> and L is reset to NULL. This is fine. There is no memory leak.

>Huu, this is not what the LRM says.
>
>LRM says:
>Procedure WRITELINE causes the current line designated by parameter L
>to be written to the file and returns with the value of parameter L
>designating a null string.
>
>If L designates a null string, it is not reset to NULL.


You're right, and I was careless. Sorry.

My point about the memory leak remains valid. But of course
there is an important difference: a LINE that designates a
null string has attributes such as 'LENGTH, but if you set
an access variable to NULL and then try to examine its
attributes you will get a bad-pointer error.

Thanks for the clarification.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:(E-Mail Removed)
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
procedure as argument in procedure AlexWare VHDL 2 10-23-2009 09:14 AM
'Procedure or function <stored procedure name> has too many arguments specified',,,ARGH! Mike P ASP .Net 0 06-19-2006 01:19 PM
wait until stored procedure is complete TJS ASP .Net 2 02-11-2004 02:22 PM
Mr. Bean Complete Bean NOT complete!! Waterperson77 DVD Video 5 12-10-2003 05:22 PM



Advertisments