Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'needed,': 0.07; 'back.': 0.09; 'obj': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'buffer.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'wrote:': 0.18; 'written': 0.21; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'instead.': 0.24; 'mon,': 0.24; 'least': 0.26; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'fixed': 0.29; 'am,': 0.29; 'reply.': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'objects': 0.35; 'thanks': 0.36; 'should': 0.36; 'example,': 0.37; 'skip:o 20': 0.38; 'question,': 0.38; 'to:addr:python-list': 0.38; 'von': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'real': 0.63; 'mar': 0.68; 'increase': 0.74; 'played': 0.84; 'received:186': 0.93; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Fabian von Romberg Subject: Re: io.BytesIO Date: Mon, 25 Mar 2013 21:43:24 -0500 References: <514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com> <514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 186.68.114.214 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1364265820 news.xs4all.nl 6906 [2001:888:2000:d::a6]:47738 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:41846 Hi Steve, thanks for your reply. Actually I played around with these methods. Whe you truncate(12468) for example, I thought the object would allocate 12468 bytes and I wanted to get that back. The methods your mention, works only for what ha been written (obj.write()). I think I should use io.BufferedWriter instead. Just one question, what has better performance: BufferedWriter or BytesIO? Thanks and regards, Fabian On 03/25/2013 01:54 AM, Steven D'Aprano wrote: > On Mon, 25 Mar 2013 00:10:04 -0500, Fabian von Romberg wrote: > >> Hi Steven, >> >> >> actually why I need is to know how much memory has been allocated for >> buffering. >> >> getsizeof gets the size of the object structure. > > I can see at least four ways to get the current size of the BytesIO > buffer: > > py> obj = io.BytesIO(b"x"*12468) > py> obj.getbuffer().nbytes > 12468 > py> len(obj.getvalue()) > 12468 > py> len(obj.getbuffer()) > 12468 > py> obj.seek(0, 2) > 12468 > > > As far as I can tell, BytesIO objects do not have a fixed size buffer. > They will increase in size as needed, just like real file objects on a > disk. > > >