On Wed, 28 Nov 2007 12:13:05 -0800 (PST), Amal wrote:
>>L is an access type and write function keeps deallocating L and
>allocating more storage (the string that L points to would grow in
>size from write to write). My question is that, normally it is best
>to release the storage pointed to by L by calling deallocate on L.
>But in this case I cannot call deallocate(L) explicitly before the
>function returns. Do simulators release the storage after the
>function returns?
I'm afraid I don't know - in this particular case, presumably,
a sufficiently clever tool could see that the access variable
L cannot be "given away" by the function and therefore it
can safely be deallocated on exit. But I agree with
you that it feels wrong.
One trick for getting around this is to move variable L
outside your function, and then wrap the whole thing in
yet another function. Like this (in which the "to_string"
function merely makes a string of N asterisks, but you'll
get the idea):
impure function to_string(n: positive) return string is
variable L: line;
impure function to_string_inner(n: positive) return string is
begin
for i in 1 to n loop
write(L, character' ('*') );
end loop;
return L.all;
end;
constant s: string := to_string_inner(n);
begin
deallocate(L);
return s;
end;
Someone else may have some nicer ideas...
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
[email protected]
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.