ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1220. Stacks

Troubles with Java
Posted by Razdolbay from SIS 23 Aug 2007 04:11
I tried to receive accept using Java...

Now I have only one trouble:
"PrintStream System.out" saves all data which is outputted.
So it uses unnecessary almost 1MB :(

If somebody knows how to cope with it, please, tell me.
Re: Troubles with Java
Posted by [SPbSPU]crazylammer 25 Aug 2007 17:43
I'm not sure, but mb calling "System.out.flush()" several times while outputing can help...
Re: Troubles with Java
Posted by Razdolbay from SIS 26 Aug 2007 12:33
Thank you :)

I already tried...
System.out is autoflushable so flush() doesn't change anything.

Edited by author 26.08.2007 12:40
Re: Troubles with Java
Posted by [SPbSPU]crazylammer 27 Aug 2007 02:05
Hm... IMHO there is no place to store the previous output in java.lang.PrintStream. I think that plenty of temporary objects are creating in some operations (using Strings) in System.out.print(...). Of course they aren't deleting by the garbage collector during one-second thread lifetime.
Try to use System.out.write(byte), it seems to be OK there. (So you have to implement some boring things...).

I also had troubles with java.lang.String... Discovering O(n) performance of operator+ was at the wrong time :).

Edited by author 27.08.2007 02:05
Re: Troubles with Java
Posted by Razdolbay from SIS 27 Aug 2007 13:03
System.out=F;

Of course, i used exactly F.write(int), it
calls F.out.write(int) where F.out is OutputStream
which F gets from its constructor.

And how F.out is implemented, i don't know...
And don't know where it can be read about :(

Btw... I tried to use garbage collector with hands, it uses 1.5M itself :(

>> I also had troubles with java.lang.String... Discovering O(n) performance of operator+ was at the wrong time :).

Thank you for experience =)

Edited by author 27.08.2007 13:05
Re: Troubles with Java
Posted by [SPbSPU]crazylammer 27 Aug 2007 13:31
Source code of all java libraries is fully avalible, there is the src.zip file in the root folder of JDK. That code isn't so complicated.

In this problem... I've tried to submit code like this:

public class A {
    public static void main(String[] args) {
        int[]a = new int[100000]; //to get ML, not OL, the size was different - I can't remember it
        for(int i = 0; i < 100000; ++i) { //also 100000 isn't true
            //System.out.print('1'); - case 1
            //System.out.write((int)'1'); - case 2
        }
    }
}


Case 1 got ML, but case 2 uses the same amount of memory like the code without any output..



Edited by author 27.08.2007 13:34