September 13th, 2013, 12:31 AM
Getting memory address of a File in HardDisk
I made a text file.
I can do all File I/O functions in c. no problem!
except that "I want to get the memory address of the begining of that File", so that I can access each character of the file by incrementing memory address.
Just a Learning Experiment
September 13th, 2013, 01:34 AM
September 13th, 2013, 03:41 PM
Files are not "in memory" and have no direct address. However in modern operating systems and processors with virtual memory capability it is possible to memory-map a file such that it appears to be in addressable memory.
Once memory mapped, you can read and write a file with random access as if it were memory, under the hood the OS handles the transfer of data and mapping between the filesystem and RAM. Your systems swap-file works like this, but you can create your own memory mapped file as well. Like the system swap file, you can have a larger virtual space that you have physical RAM available, and like the system swap-file doing so will be considerably slower than physical RAM.
Memory mapped files can also be used as a means of sharing data between multiple separate processes.
The API for memory-mapped files varies between operating systems.
The basic Win32 API and a detailed explanation can be found here though the article is quite old, it still stands. More or less the same informaton, but with perhaps a poorer description of the details can be found here. The .NET framework provides a more modern API described here
In POSIX operating systems such as Linux or OSX you can use mmap()
For an OS independent memory mapped file API you can use boost.