Concatenate TEXTIO line type

  • Thread starter Andrew Greensted
  • Start date
A

Andrew Greensted

Guest
Hi All,

I'm using the textio functions to log some generated data to a file.
The problem is I need to:
- buffer some data
- write out a buffer length counter
- write out the buffer

Essentially I have:

file outputFile : text open WRITE_MODE is "dataFile.dat";
variable lineTMP : line;
variable lineOut : line;

write(lineTMP, somedata);
write(lineTMP, someMoreData); etc....

count <= b"10";

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));

writeLine(outputFile, lineOut);
writeLine(outputFile, lineTMP);

However, there is a new line between lines. Is there some way to
concatenate the lines before doing the write? Note, I don't know the
count value until I've received all the buffered data.

If I could convert lineTMP to a string, I could just write this out to
lineOUT, before the writeLine call.

Thanks
Andy
 
On Feb 6, 10:37 am, Andrew Greensted <ajg...@ohm.york.ac.uk> wrote:

If I could convert lineTMP to a string, I could just write this out to
lineOUT, before the writeLine call.
In the standard textio package, a line is nothing more than a pointer
(an access type) to a string. This would suggest you could get the
string just by adding a '.all' to the line variable, and catenate two
lines (very explicitly) using something like:

line3.all := line1.all & line2.all;

This is effectively all that "write" does at its core.

- Kenn
 
kennheinrich@sympatico.ca wrote:

line3.all := line1.all & line2.all;

This is effectively all that "write" does at its core.

- Kenn
Hi Kenn,

This works really well, but I now have a slightly different problem!

I now have:

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));
write(lineOut, string'(lineTmp.all));
writeLine(outputFile, lineOut);

The problem is that lineTmp, is not getting 'reset'

You say the Line is effectively a pointer to a String type. Is it
possible to reset this pointer to the start of the string?

Thanks
Andy
 
Hi Kenn,

This works really well, but I now have a slightly different problem!

I now have:

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));
write(lineOut, string'(lineTmp.all));
writeLine(outputFile, lineOut);

The problem is that lineTmp, is not getting 'reset'

You say the Line is effectively a pointer to a String type. Is it
possible to reset this pointer to the start of the string?

Thanks
Andy
After a bit of reading:

deallocate(lineTMP);
lineTMP := null;

Is that right? It certainly seems to do what I'm after. But is it memory
leak safe?

Andy
 
Andrew Greensted wrote:
Hi Kenn,

This works really well, but I now have a slightly different problem!

I now have:

hwrite(lineOut, std_logic_vector(to_unsigned(count, 8)));
write(lineOut, string'(": "));
write(lineOut, string'(lineTmp.all));
writeLine(outputFile, lineOut);

The problem is that lineTmp, is not getting 'reset'

You say the Line is effectively a pointer to a String type. Is it
possible to reset this pointer to the start of the string?

Thanks
Andy

After a bit of reading:

deallocate(lineTMP);
lineTMP := null;

Is that right? It certainly seems to do what I'm after.
Deallocate should leave lineTMP null so you should not need
to assign lineTMP to null.

But is it memory leak safe?
Yes. deallocate is exactly what writeline does.

Jim
 
Jim Lewis wrote:

After a bit of reading:

deallocate(lineTMP);
lineTMP := null;

Is that right? It certainly seems to do what I'm after.
Deallocate should leave lineTMP null so you should not need
to assign lineTMP to null.

But is it memory leak safe?
Yes. deallocate is exactly what writeline does.
No, not exactly. ;-)

From the LRM 93: "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."

So L will not be NULL, it will point to a null string. And even a null
string keeps some memory allocated.

Especially if L (or lineTMP) is declared locally in a subprogram, you must
use deallocate to free this memory to avoid a memory leak. If L is declared
in a process, this will not be necessary.

I'm not sure whether the behaviour of writeline is still the same in the
2002 VHDL version.

--
Paul Uiterlinden
www.aimvalley.nl
 

Welcome to EDABoard.com

Sponsor

Back
Top