473,327 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Question about the built-in file() and buffer size...

The documentation for file() says that the buffer size will be:

system default if bufsize == -1,
unbuffered if bufsize == 0,
line buffered if bufsize == 1,
or else it is just bufsize.

I can't get this last one to work... if I write something like:
test = file("testfile","w",1024)
test.write("a"*1025);


the file "testfile" is not written to... it only gets written to when
the buffer size reaches 4096 bytes, which is the system default from
what I can ascertain. It doesn't work if I set bufsize to be larger
than 4096 either, it will get written when it reaches 4096 bytes no
matter what.

Am I doing something wrong? Is this option not implemented all the
way (the -1,0,1 seem to work fine... except that 1 is also 4096 byte
buffered, in addition to being line buffered)?

Thanks :)
Darby
Jul 18 '05 #1
1 3161
On Wed, Feb 04, 2004 at 03:14:23PM -0800, Darby Wong wrote:
The documentation for file() says that the buffer size will be:

[...]

The buffer size argument is merely passed along to a call to setvbuf
as the "size" argument, like so:
+setvbuf(0x0815e780, NULL, 0, 1024) = 0
So it's beyond the control of Python. Apparently your C library
disregards the actual size parameter given and choose another size
(perhaps related to the OS page size or the filesystem block size).

This behavior is different between 2.2.2 from redhat9 and python CVS.
In CVS, the buffer is allocated by Python:
setvbuf(0x082089d0, 0x08183338, 0, 1024) = 0
I don't know if 2.3 behaves like 2.2 or like this CVS release. This
might give the behavior you're interested in, but it's still safer to
use .flush() at the right time, because either the C standard doesn't
guarantee much, or C libraries aren't very good.

Jeff

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Ioannis Vranos | last post by:
When we use the standard placement new operator provided in <new>, and not a definition of owr own, isn't a call to placement delete enough? Consider the code: #include <new>
2
by: derek.google | last post by:
I have an application that's crashing because of an alignment problem, and this is the smallest program that demonstrates what's happening: int main() { struct Message { unsigned short size;...
22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
3
by: fernandez.dan | last post by:
My question is about if I should return char* or have a char* as an argument. My basic premise for this function is to return a char* buffer and the size of the buffer to the caller. I know that...
1
by: ad | last post by:
I want to write a MemoryStream to a buffer. I use the codes below; The code is from the msdn help, They always declare the size of buffer as the (length of memorystream)+1; The code run ok, but...
6
by: Bruce Adcock | last post by:
Hi, I have run across the some strange syntax, to which I do not understand the meaning: const char* xmlHeader = {"<?xml"}; (specifically, this can be found in "tinyxmlparse.cpp", Line 828,...
4
by: Scott F. Brown | last post by:
Greetings all... I was playing around with compressing streams and came across a behavior that I do not understand. I create a stream (input) from the contents of a textbox. That stream is...
26
by: Andrew Poelstra | last post by:
I hacked this together this morning so that I could shift my out-of- space code away from the rest of my logic. I wanted to allow array syntax on my dynamic buffers, so I manually created a struct...
4
by: Angus | last post by:
Hello I am writing a sampling type program which takes a buffer, and picks the middle of the buffer. But I need to take a bit out the middle and then take what is left (on both sides) and take...
3
by: Chris | last post by:
Hi, I'm using CGI with MS IIS and Visual Studio 2003. My problem is when I'm trying to read post data, I use cin.get(buffer, size), where buffer is a new char and size is the atoi of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.