Good afternoon. I use FileMapping to read files. And now I need to create a file using this technology, but I don't know the size of the file. How can I use FileMappimg to create files, if there sizes are unknown?
Asked
Active
Viewed 457 times
-1
-
1Create a file using file mapping. What does that mean? – Sertac Akyuz Nov 15 '13 at 13:01
-
@user2996299 Why you don't use TFileStream? – kot-da-vinci Nov 15 '13 at 13:05
-
@user2819514, because files over 8Gb. – user2996299 Nov 15 '13 at 13:10
-
3Why is 8GB important? [`TFileStream`](http://docwiki.embarcadero.com/Libraries/XE5/en/System.Classes.TFileStream) has a [64-bit file pointer](http://docwiki.embarcadero.com/Libraries/XE5/en/System.Classes.TStream.Position) like all `TStream` descendants - it can handle *huge* files. – David Nov 15 '13 at 13:25
-
TFileStream can be used to create files larger than 8GB. I tested this by creating a 25GB file, just to make sure. (XE5 Windows7) – Bruce McGee Nov 15 '13 at 14:24
1 Answers
2
You have to know in advance how large the file is when you call CreateFileMapping. So I guess you'd need to pick a large value, and if you run out of space, close that mapping, and create a new one with a larger max size. That's not much fun and probably not terribly efficient.
Most likely you simply don't realise that Delphi file streams can work with huge files with 64 bit file pointers. And perhaps you have performance reasons for using mappings. In which case you just need a buffered stream, of which there are many freely available examples.

David Heffernan
- 601,492
- 42
- 1,072
- 1,490