mmap on MacOS

let’s see a snippet of code, Guess what happened on MacOS ?

 size_t pageSize = getpagesize();

  std::cout << " page size is " << pageSize << std::endl;

  int handle = shm_open("mempool_tag", O_CREAT | O_RDWR , 0777 );

  if (handle) {
     std::cout << std::setw(20) << "shm_open yield with  " << handle << std::endl;
  }
  else {
     ftruncate(handle, GetPoolSize());  
  }
  
  ftruncate(handle, GetPoolSize());  

  char* region = (char*) mmap( NULL, 
                               GetPoolSize(),
                               PROT_READ | PROT_WRITE | PROT_EXEC,
                               MAP_ANONYMOUS,
                               handle,
                               GetPoolSize()*20);
  if (region == MAP_FAILED) {
     return -1; 
  }

  return 0;

0 thoughts on “mmap on MacOS”

发表评论

电子邮件地址不会被公开。 必填项已用*标注