pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vadim Nasardinov <vadimn@redhat.com>
To: Sebastiaan van Erk <sebster@sebster.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: ps.setCharacterStream() and memory usage
Date: Tue, 2 Nov 2004 11:55:22 -0500
Message-ID: <200411021155.22490@vadim.nasardinov> (raw)
In-Reply-To: <20041029115651.GE4199@sebster.com>
References: <20041029115651.GE4199@sebster.com>

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




view thread (6+ messages)  latest in thread

Message-ID: <200411021155.22490@vadim.nasardinov>
Permalink:  ../200411021155.22490@vadim.nasardinov/
Also on:    postgresql.org/message-id/200411021155.22490@vadim.nasardinov

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: vadimn@redhat.com, sebster@sebster.com
  Subject: Re: ps.setCharacterStream() and memory usage
  In-Reply-To: <200411021155.22490@vadim.nasardinov>
  References: <20041029115651.GE4199@sebster.com> <200411021155.22490@vadim.nasardinov>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox