Reputation: 2486
f = open('somefile')
f.seek(0, 2)
f.tell()
Above code will
1. open a pointer point to a file
2. move the pointer from file start to end
3. return the bytes that the pointer moved
Question 1:
Since the pointer will be moved from file start to end, does this mean OS have to load the file from disk into memory?
Question 2:
Since the pointer will be moved from file start to end, does the time spend on step 2 will be directly related to the size of the file?
Upvotes: 0
Views: 73
Reputation: 409404
For random-access filesystems, the "current position" (the "pointer" you change by seeking) is a simple unsigned integer variable that usually only contains an offset (in bytes) from the start of the file.
When you seek this offset is modified (added to or subtracted from, or set to an absolute value).
Seeking to the end is simply setting the offset to the size of the file.
Upvotes: 1
Reputation: 223062
Since the pointer will be moved from file start to end, does this mean OS have to load the file from disk into memory?
No. Current filesystem implementations are not sequential, they allow random seeking through the file.
Since the pointer will be moved from file start to end, does the time spend on step 2 will be directly related to the size of the file?
No. No physical pointer is being actually moved, it is just a variable in memory.
Upvotes: 1