How to set the compiler to handle thousand loops ?

R

RedGrittyBrick

tobleron said:
I see... here is the .java file http://www.artikelilmiah.com/NewECGRecord-Java.zip
Sorry for the misunderstanding...

while ((text = reader.readLine()) != null)
{
contents.append(text)
.append(System.getProperty(
"line.separator"));
jumlahline++;
}

In the above loop, you save the whole signal file in a StringBuffer
which you later convert to a String. You then use Scanner on that String.

I'd not append each line to a StringBuffer. I'd process each line
separately within the above loop. That way you don't have to store the
entire file in some variable, just one record.

I'm assuming it is possible to process one line independently of those
preceding or following it.



P.S. It appears you are using indentation to show the structure of the
output record and not the structure of the program. This makes it hard
to read. I think you could usefully break the program up into smaller
methods and investigate some way of reducing the amount of repetitive code.
 
L

Lew

tobleron wrote:

You forgot to attribute the quote.

I see... here is the .java file http://www.artikelilmiah.com/NewECGRecord-Java.zip
Sorry for the misunderstanding...

This is still not an SSCCE, as several of us have advised providing.

For Usenet posts, please use much gentler indentation.
{
reader = new BufferedReader(new FileReader(file2));
String text = null;

// repeat until all lines is read
while ((text = reader.readLine()) != null)
{
contents.append(text).append(System.getProperty( "line.separator"));
jumlahline++;
}
....

Here is your problem, just as Martin Gregorie figured. He advised:
Otherwise, why buffer entire files when you appear to be processing the
data line by line? Read from the file line by line and output each
converted line as its completed and your memory problems will vanish.

Of course you're going to run out of memory if you read too much into memory
all at once.

If you insist on reading the entire file into memory, then you will need to
increase -Xmx until it covers your memory needs.

Do provide SSCCEs in the future. You are asking people to help you, it only
makes sense to make it easy for them to do so.
 
T

tobleron

   while ((text = reader.readLine()) != null)
   {
      contents.append(text)
      .append(System.getProperty(
      "line.separator"));
      jumlahline++;
   }

In the above loop, you save the whole signal file in a StringBuffer
which you later convert to a String. You then use Scanner on that String.

I'd not append each line to a StringBuffer. I'd process each line
separately within the above loop. That way you don't have to store the
entire file in some variable, just one record.

I'm assuming it is possible to process one line independently of those
preceding or following it.

P.S. It appears you are using indentation to show the structure of the
output record and not the structure of the program. This makes it hard
to read. I think you could usefully break the program up into smaller
methods and investigate some way of reducing the amount of repetitive code.

But, I need to write the DICOM VR whith the structure like this : tag;
VR; length; value. The first loop is to find the length (jumlahline++)
and the second loop is to write the value, channel by channel (each
line contains 12 channels). If I use one loop only, how can I write
the length before the value ? The DICOM stream should be written in
sequential. Do you have another suggestion about this ?
 
D

Donkey Hottie

But, I need to write the DICOM VR whith the structure like this : tag;
VR; length; value. The first loop is to find the length (jumlahline++)
and the second loop is to write the value, channel by channel (each
line contains 12 channels). If I use one loop only, how can I write
the length before the value ? The DICOM stream should be written in
sequential. Do you have another suggestion about this ?

while ((text = reader.readLine()) != null)
{
  jumlahline++;
}

Add that loop to the beginning, and there you have it.
 
R

RedGrittyBrick

Please delete quoted paragraphs like the above which are not relevant to
your follow-up questions.

Please don't quote sigs, do delete them when replying.
But, I need to write the DICOM VR whith the structure like this : tag;
VR; length; value. The first loop is to find the length (jumlahline++)
and the second loop is to write the value, channel by channel (each
line contains 12 channels). If I use one loop only, how can I write
the length before the value ? The DICOM stream should be written in
sequential. Do you have another suggestion about this ?

In order to understand the above question I'd have to re-read your code.
I am a bit reluctant to do this as it is so large and monolithic.

If you need a "length" of something (line count?) then just read the
file twice, first to count lines (for your preamble for your output
file) and the second time to emit the output records.

This isn't good but it is probably better than storing everything in
memory. Trade I/O for RAM. Measure elapsed time if that becomes an issue.

If the input file has fixed length records (I haven't looked) then you
can just obtain the file size and divide by record length to get the
record count. That way you only need to read the file once.

Another way would be to write the output records to a temp file without
any preamble, accumulate the data for the preamble as you go. At the
end, append the temp file to the preamble. I'm not sure there is any
saving in I/O (it's probably worse) but it may be worth considering.

Sorry if the above suggestions don't match your situation. I'm reluctant
to spend hours of effort on this.

If you can create a concise SSCCE and a good terse description of the
input and output formats then you'll make it easier for people to help you.

John B Matthews' suggestion of prior art seems like an excellent avenue
of research for you.
 
T

tobleron

@All,

I've followed your suggestions, and the problem has been solved. Thank
you very much for your helps.

Best regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,444
Messages
2,571,710
Members
48,796
Latest member
Greg L.
Top