Sakshi Gupta
Sakshi Gupta

Reputation: 51

use of undeclared identifier 'MAP_POPULATE'

When using mmap on Mac OS X and Xcode I am getting the error:

use of undeclared identifier 'MAP_POPULATE'

The same code is working on another machine. How do I fix this?

Upvotes: 5

Views: 2320

Answers (1)

gui11aume
gui11aume

Reputation: 2948

MAP_POPULATE is available only on Linux and only since version 2.5.46 (since version 2.6.23 for private mappings). MAP_POPULATE is used to reduce the penalty of page faults, so your code should be able to run without. Here is an example of how you can use the preprocessor to run the same code on different machines.

#if __linux__
#include <linux/version.h>
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22)
#define _MAP_POPULATE_AVAILABLE
#endif
#endif

#ifdef _MAP_POPULATE_AVAILABLE
#define MMAP_FLAGS (MAP_PRIVATE | MAP_POPULATE)
#else
#define MMAP_FLAGS MAP_PRIVATE
#endif

Upvotes: 4

Related Questions