| From: | Vadim Nasardinov <vadimn(at)redhat(dot)com> |
|---|---|
| To: | Sebastiaan van Erk <sebster(at)sebster(dot)com>, pgsql-jdbc(at)postgresql(dot)org |
| Subject: | Re: ps.setCharacterStream() and memory usage |
| Date: | 2004-11-02 16:55:22 |
| Message-ID: | 200411021155.22490@vadim.nasardinov |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
On Friday 29 October 2004 07:56, Sebastiaan van Erk wrote:
> ps.setCharacterStream(1, reader, (int) messageFile.length());
> ps.executeUpdate();
>
> The reason I do this (using a character stream to load a text file
> to a TEXT field) is that I wish to avoid loading the file into
> memory completely.
By doing this, you may overallocate. Note that File#length() [1]
returns the length of the file in _bytes_.
AbstractJdbc2Statement#setCharacterStream uses the passed in number to
allocate a _character_ array of that length. If your file is encoded
in, say, UTF-16, its byte length is twice its character length. Half
of the character array allocated by the setCharacterStream method is
wasted in this case.
Vadim
Footnotes
1. http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html#length%28%29
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Alan Stange | 2004-11-02 17:05:34 | Re: executeBatch() issue with new driver? |
| Previous Message | Ron St-Pierre | 2004-11-02 16:50:36 | Re: JDeveloper |