• Post Reply Bookmark Topic Watch Topic
  • New Topic

flush() and memory

 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,
flush() forces any buffered output characters to be written out, else it will consume memory resource.
1. How do I know, size of the buffer I can read data into, before I invoke flush().
ex.

PrintWriter out = PrintWriter()
out.flush();


2. How do I know, how much memory resource it is taking, if I don't flush(). Specially in UNIX.

Thanks you very much.
siva
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't call flush(), when the buffer fills up, it will be called automatically. Furthermore, the buffer probably won't be freed when flush() is called, so calling it will have no effect at all on resource consumption.

The purpose of flush() is to make sure that all data has been transmitted without closing the stream -- for example, during two-way communication over a socket.

If the buffer is from a BufferedWriter, then you can specify the buffer size when you construct the BufferedWriter. Otherwise a default size is used -- I think it was 4096 bytes the last time I checked.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the I/O and Streams forum...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!