Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41812 > unrolled thread

io.BytesIO

Started byFabian von Romberg <fromberg100@hotmail.com>
First post2013-03-24 22:56 -0500
Last post2013-03-25 21:43 -0500
Articles 5 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  io.BytesIO Fabian von Romberg <fromberg100@hotmail.com> - 2013-03-24 22:56 -0500
    Re: io.BytesIO Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-25 04:47 +0000
      Re: io.BytesIO Fabian von Romberg <fromberg100@hotmail.com> - 2013-03-25 00:10 -0500
        Re: io.BytesIO Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-03-25 06:54 +0000
          Re: io.BytesIO Fabian von Romberg <fromberg100@hotmail.com> - 2013-03-25 21:43 -0500

#41812 — io.BytesIO

FromFabian von Romberg <fromberg100@hotmail.com>
Date2013-03-24 22:56 -0500
Subjectio.BytesIO
Message-ID<mailman.3688.1364183789.2939.python-list@python.org>
Hi,

is there any way to get the allocated memory size from a io.BytesIO object?

Thanks and regards,
Fabian

[toc] | [next] | [standalone]


#41813

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-03-25 04:47 +0000
Message-ID<514fd6d3$0$29998$c3e8da3$5496439d@news.astraweb.com>
In reply to#41812
On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote:

> Hi,
> 
> is there any way to get the allocated memory size from a io.BytesIO
> object?

The same as for any object:

py> import io, sys
py> obj = io.BytesIO()
py> sys.getsizeof(obj)
48


Is this what you are after, the size of the object itself, including any 
overhead?


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#41814

FromFabian von Romberg <fromberg100@hotmail.com>
Date2013-03-25 00:10 -0500
Message-ID<mailman.3689.1364188221.2939.python-list@python.org>
In reply to#41813
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.

For example, if I do io.BytesIO.truncate(10000), it will resize the buffer to 10000 bytes.  So my question is how to get those 10000 back from an attribute or method?

Regards,
Fabian

On 03/24/2013 11:47 PM, Steven D'Aprano wrote:
> On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote:
> 
>> Hi,
>>
>> is there any way to get the allocated memory size from a io.BytesIO
>> object?
> 
> The same as for any object:
> 
> py> import io, sys
> py> obj = io.BytesIO()
> py> sys.getsizeof(obj)
> 48
> 
> 
> Is this what you are after, the size of the object itself, including any 
> overhead?
> 
> 

[toc] | [prev] | [next] | [standalone]


#41816

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-03-25 06:54 +0000
Message-ID<514ff48f$0$29998$c3e8da3$5496439d@news.astraweb.com>
In reply to#41814
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.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#41846

FromFabian von Romberg <fromberg100@hotmail.com>
Date2013-03-25 21:43 -0500
Message-ID<mailman.3711.1364265820.2939.python-list@python.org>
In reply to#41816
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.
> 
> 
> 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web