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 1C78A3A3F0F for ; Tue, 2 Nov 2004 16:49:17 +0000 (GMT) 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 16078-02 for ; Tue, 2 Nov 2004 16:49:15 +0000 (GMT) Received: from mx1.redhat.com (mx1.redhat.com [66.187.233.31]) by svr1.postgresql.org (Postfix) with ESMTP id 997133A3EDE for ; Tue, 2 Nov 2004 16:49:14 +0000 (GMT) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id iA2GnDcW006253; Tue, 2 Nov 2004 11:49:13 -0500 Received: from mail.boston.redhat.com (mail.boston.redhat.com [172.16.76.12]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id iA2GnDr19347; Tue, 2 Nov 2004 11:49:13 -0500 Received: from 192.168.1.2 (vpn83-126.boston.redhat.com [172.16.83.126]) by mail.boston.redhat.com (8.12.8/8.12.8) with ESMTP id iA2GnBFE002035; Tue, 2 Nov 2004 11:49:11 -0500 From: Vadim Nasardinov Organization: Red Hat / Westford To: Sebastiaan van Erk , pgsql-jdbc@postgresql.org Subject: Re: ps.setCharacterStream() and memory usage Date: Tue, 2 Nov 2004 11:55:22 -0500 User-Agent: KMail/1.5.4 References: <20041029115651.GE4199@sebster.com> In-Reply-To: <20041029115651.GE4199@sebster.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200411021155.22490@vadim.nasardinov> 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: 200411/22 X-Sequence-Number: 11444 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