fseek

Question about file seeking position

僤鯓⒐⒋嵵緔 提交于 2019-12-01 08:53:18
问题 My previous Question is about raw data reading and writing, but a new problem arised, it seems there is no ending.... The question is: the parameters of the functions like lseek() or fseek() are all 4 bytes. If i want to move a span over 4G, that is imposible. I know in Win32, there is a function SetPointer(...,Hign, Low,....) , this pointers can generate 64 byte pointers, which is what i want. But if i want to create an app in Linux or Unix (create a file or directly write the raw drive

should I use fseek SEEK_END [duplicate]

人盡茶涼 提交于 2019-12-01 08:21:42
This question already has an answer here: How do you determine the size of a file in C? 14 answers My question is simple: Should I use fseek with SEEK_END to get to the end of a file and then get the length of it ? Because in the man it is said: Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability). Right now I am using stat (from C) which is better ? The ftell function returns a long, which means that on an ILP32 system you can't correctly get the size of a file larger than 2GB. You should use the stat function or

should I use fseek SEEK_END [duplicate]

こ雲淡風輕ζ 提交于 2019-12-01 07:09:04
问题 This question already has answers here : How do you determine the size of a file in C? (14 answers) Closed 5 years ago . My question is simple: Should I use fseek with SEEK_END to get to the end of a file and then get the length of it ? Because in the man it is said: Library implementations are allowed to not meaningfully support SEEK_END (therefore, code using it has no real standard portability). Right now I am using stat (from C) which is better ? 回答1: The ftell function returns a long,

Fastest way to read every 30th byte of large binary file?

左心房为你撑大大i 提交于 2019-11-30 11:24:35
问题 What is the fastest way to read every 30th byte of a large binary file (2-3 GB)? I've read there are performance problems with fseek because of I/O buffers, but I don't want to read 2-3 GB of data into memory before grabbing every 30th byte either. 回答1: Performance test. If you want to use it yourself, note that the integrity check (printing total) only works if "step" divides BUFSZ, and MEGS is small enough that you don't read off the end of the file. This is due to (a) laziness, (b) desire

How is fseek() implemented in the filesystem?

让人想犯罪 __ 提交于 2019-11-30 06:45:08
This is not a pure programming question, however it impacts the performance of programs using fseek(), hence it is important to know how it works. A little disclaimer so that it doesn't get closed. I am wondering how efficient it is to insert data in the middle of the file. Supposing I have a file with 1MB data and then I insert something at the 512KB offset. How efficient would that be compared to appending my data at the end of the file? Just to make the example complete lets say I want to insert 16KB of data. I understand the answer varies depending on the filesystem, however I assume that

Fastest way to read every 30th byte of large binary file?

旧时模样 提交于 2019-11-30 00:08:10
What is the fastest way to read every 30th byte of a large binary file (2-3 GB)? I've read there are performance problems with fseek because of I/O buffers, but I don't want to read 2-3 GB of data into memory before grabbing every 30th byte either. Steve Jessop Performance test. If you want to use it yourself, note that the integrity check (printing total) only works if "step" divides BUFSZ, and MEGS is small enough that you don't read off the end of the file. This is due to (a) laziness, (b) desire not to obscure the real code. rand1.data is a few GB copied from /dev/urandom using dd .

Flushing fopen()'ed files opened in update mode,between read and write operations.Explicit flushing needed?

ⅰ亾dé卋堺 提交于 2019-11-29 14:56:02
I have read this about the switch between read and write operations(and vice-versa) for files opened for update using fopen() ( LINK ) "For files open for update (those which include a "+" sign), on which both input and output operations are allowed, the stream should be flushed (fflush) or repositioned (fseek, fsetpos, rewind) between either a writing operation followed by a reading operation or a reading operation which did not reach the end-of-file followed by a writing operation." There are two things mentioned here that I would like to highlight the stream should be flushed (fflush) or

Complexity of f.seek() in Python

青春壹個敷衍的年華 提交于 2019-11-29 13:41:53
Does f.seek(500000,0) go through all the first 499999 characters of the file before getting to the 500000th? In other words, is f.seek(n,0) of order O(n) or O(1)? You need to be a bit more specific on what type of object f is. If f is a normal io module object for a file stored on disk, you have to determine if you are dealing with: The raw binary file object A buffer object, wrapping the raw binary file A TextIO object, wrapping the buffer An in-memory BytesIO or TextIO object The first option just uses the lseek system call to reposition the file descriptor position. If this call is O(1)

Does fseek() move the file pointer to the beginning of the file if it was opened in “a+b” mode?

萝らか妹 提交于 2019-11-29 09:25:40
I wish to open a file using the "a+b" mode, i.e. if it does not exist it is created automatically, but if it does I don't want to overwrite it. I want to be able to read and write to the file. The file is binary, and I want to save records of a specific struct in it. So I want to do fseek() to the record I want and then save the record using fwrite() . The code looks as follows ( MyRecord is a typedef to a struct , while FILENAME is a #define to the file's name): int saveRecord(MyRecord *pRecord, int pos) { FILE* file = fopen(FILENAME, "a+b"); if (file == NULL) { printf("Unable to open file %s

How is fseek() implemented in the filesystem?

懵懂的女人 提交于 2019-11-29 05:56:06
问题 This is not a pure programming question, however it impacts the performance of programs using fseek(), hence it is important to know how it works. A little disclaimer so that it doesn't get closed. I am wondering how efficient it is to insert data in the middle of the file. Supposing I have a file with 1MB data and then I insert something at the 512KB offset. How efficient would that be compared to appending my data at the end of the file? Just to make the example complete lets say I want to