Welcome to mirror list, hosted at ThFree Co, Russian Federation.

probing_hash_utils.cpp « ProbingPT « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ca3e8f69f8bb0eb0c67b4c48f6af141e2327b6dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "probing_hash_utils.hh"

//Read table from disk, return memory map location
char * readTable(const char * filename, size_t size)
{
  //Initial position of the file is the end of the file, thus we know the size
  int fd;
  char * map;

  fd = open(filename, O_RDONLY);
  if (fd == -1) {
    perror("Error opening file for reading");
    exit(EXIT_FAILURE);
  }

  map = (char *)mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);

  if (map == MAP_FAILED) {
    close(fd);
    perror("Error mmapping the file");
    exit(EXIT_FAILURE);
  }

  return map;
}


void serialize_table(char *mem, size_t size, const char * filename)
{
  std::ofstream os (filename, std::ios::binary);
  os.write((const char*)&mem[0], size);
  os.close();

}