47

Is there an api to do memory mapping, just like

mmap()

on linux?

Mark Pim
  • 9,898
  • 7
  • 40
  • 59
Fernandez
  • 471
  • 1
  • 4
  • 3
  • I use `calloc(1, size)`. It never fails to be the fastest general-purpose allocator. And it can allocate an obscene amount of memory. And it will provoke disk paging if need be. – Chef Gladiator Oct 11 '22 at 20:58

1 Answers1

26

Depends on what exactly you want to use it for. If you want to map existing files into memory, that's supported with memory-mapped files. They can also be used to share memory between processes (use named mapping object with no underlying file). If you want to map physical memory, that's generally not supported from user mode, although there are some tricks.

Igor Skochinsky
  • 24,629
  • 2
  • 72
  • 109
  • 3
    I just want map a file to memory so that i can get higher I/O performance – Fernandez Nov 03 '10 at 13:48
  • @IgorSkochinsky: [CreateFileMapping](http://msdn.microsoft.com/en-us/library/aa366537(v=vs.85).aspx) "If hFile is INVALID_HANDLE_VALUE... CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system." Is that what you meant by "mapping physical memory"? – Mooing Duck Mar 15 '13 at 00:04
  • @MooingDuck nope, "backed by the system paging file" still means virtual memory; you're not guaranteed a specific place in physical memory and your mapping can be paged out or moved any time the OS feels like it. See [here](http://blogs.msdn.com/b/oldnewthing/archive/2013/03/01/10398358.aspx). – Igor Skochinsky Mar 15 '13 at 00:16
  • 1
    @IgorSkochinsky: huh, I didn't know `mmap` could do that. – Mooing Duck Mar 15 '13 at 00:41
  • I also need something like mmap to make my computer believe that RAM = free disk. I want to use it with R (or other statistics software) in order to perform some calculations with large datasets (50GB). But I need not only to map the source data but also all the memory used by the program – skan Mar 14 '15 at 21:22