X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3AFBD3A3BA4 for ; Fri, 29 Oct 2004 22:29:13 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82247-05 for ; Fri, 29 Oct 2004 21:29:02 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id 1F1B73A3BC3 for ; Fri, 29 Oct 2004 22:29:02 +0100 (BST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1CNeIs-0005Bv-00; Sat, 30 Oct 2004 10:28:58 +1300 Message-ID: <4182B65F.6000905@opencloud.com> Date: Sat, 30 Oct 2004 10:30:07 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 0.8 (X11/20041021) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sebastiaan van Erk Cc: pgsql-jdbc@postgresql.org Subject: Re: ps.setCharacterStream() and memory usage References: <20041029115651.GE4199@sebster.com> In-Reply-To: <20041029115651.GE4199@sebster.com> X-Enigmail-Version: 0.86.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/310 X-Sequence-Number: 11415 Sebastiaan van Erk wrote: > ps.setCharacterStream(1, reader, (int) messageFile.length()); > ps.executeUpdate(); > I already noticed that the postgres driver does not stream the data to > the backend (I don't know if postgres actually supports this). Character streams are going to be hard to support as we need to know the length, in bytes, of the parameter before we start sending it to the backend. With a character stream the number of bytes is unpredictable because it's being encoded into UTF8, which has a variable number of bytes per character. Binary streams we can stream, and the development driver already does so without intermediate copies. > First of all, in setCharacterStream() it loads the file into a char array. > Then this is cloned into a String and passed to setString. (Here one can > already cause the char[] to go out of scope, at least allowing it to be > cleaned up). Secondly, setString causes another clone in escapeString(). [...] I suggest you look at the current development driver before looking at solutions in this area. The parameter storage mechanisms have changed substantially compared to the stable driver. It should be much easier to, for example, encode the stream directly into a bytearray, then write from that array to the server on demand. -O