![]() ![]() This is doable, but both awkward and dangerous IMHO. you close the file), you will keep using an invalid pointer reference as a key unless you also remove the file from the map. Second, if for some reason you deallocate the file handle (i.e. It comes from some memory allocation within the sdtio library, and you have no control over it. For one thing, the pointer is just like a random number to you. However, it is pretty dangerous to do so. You could use a FILE *, though, since any pointer can be used as a map key. the FILE class does not implement the necessary comparison operator. ![]() ![]() it would not make any sense to use an unknown structure of an unknown size whose lifetime you have no direct control of as a key.Seeking back and forth like crazy between two different parts of a big file could eventually force the disk driver to wobble between two physical parts of the disk, reducing your I/O performance dramatically (unless the disk is a non-seeking device like an SSD). This is one more reason among thousands to check system calls, by the way.Īssuming the second call succeeded you can,for instance, seek to a given position with pFile1 while you read from another with pFile2.Īs a side note, since you will eventually access the same physical disk, it is rarely a good idea to do so unless you know exactly what you're doing. the system allows a second opening, i, which case pFile2 will point to a different context.the system forbids opening the file twice, in which case pFile2 will be NULL.You can say that pFile1 != pFile2, because 2 things can happen: (edited after reading the pertinent remark of Grijesh Chauhan) Many applications open a file multiple times to read concurrently (of-course if you wants writing operation also then you may need concurrency control mechanism, but that's a different matter). Although this isn't a problem on POSIX compliant systems. Therefore, portable code cannot depend on what will happen if this rule is violated. FILE fopen(const char filename, const char mode) Parameters filename This is the C string containing the name of the file to be opened. Declaration Following is the declaration for fopen () function. Some platforms may forbid a file simultaneously being opened multiple times, but other platforms may allow it. The C library function FILE fopen (const char filename, const char mode) opens the filename pointed to, by filename using the given mode. Open multiple times is also implementation-defined. Whether the same file can be simultaneously The rules for composing valid file names are Subclause 7.21.3, paragraph 8 :įunctions that open additional (nontemporary) files require a file Note opening a file that is already open has implementation-defined behavior, according to the C Standard: FIO31-C. No pFile1 and pFile2 are pointers to two distinct FILE structures, returned by the two different function calls. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |