367
132
133
/* translate the message */
134
const int lang_num = (sizeof(hello_str) / sizeof(hello_
str[0]));
135
enum lang_t lang = (enum lang_t)((hello->lang + 1) %
lang_num);
136
write_hello_str(hello, lang);
137
}
138
139
/* write message to the remote pool */
140
ret = rpmem_persist(rpp, hello_off, sizeof(*hello), 0, 0);
141
printf("%s\n", hello->str);
142
assert(ret == 0);
143
144
/* close the remote pool */
145
ret = rpmem_close(rpp);
146
assert(ret == 0);
147
148
/* release local memory pool */
149
free(pool);
150
return 0;
151
}
• Line 68: Simple helper routine for writing message to the local memory.
• Line 115: Allocate a big enough block of memory, which is aligned
to the page size. The required block size is hard-coded, whereas
the alignment is required if you want to make this memory block
available for RDMA transfers.
• Line 122: The remote_open() routine creates or opens the remote
memory pool.
• Lines 126-127: The local memory pool is initialized here. It is
performed only once when the remote memory pool was just
created, so it does not contain any message.
• Line 130: A message from the remote memory pool is read to the
local memory here.
Chapter 18 remote persistent memory
132
133
/* translate the message */
134
const int lang_num = (sizeof(hello_str) / sizeof(hello_
str[0]));
135
enum lang_t lang = (enum lang_t)((hello->lang + 1) %
lang_num);
136
write_hello_str(hello, lang);
137
}
138
139
/* write message to the remote pool */
140
ret = rpmem_persist(rpp, hello_off, sizeof(*hello), 0, 0);
141
printf("%s\n", hello->str);
142
assert(ret == 0);
143
144
/* close the remote pool */
145
ret = rpmem_close(rpp);
146
assert(ret == 0);
147
148
/* release local memory pool */
149
free(pool);
150
return 0;
151
}
• Line 68: Simple helper routine for writing message to the local memory.
• Line 115: Allocate a big enough block of memory, which is aligned
to the page size. The required block size is hard-coded, whereas
the alignment is required if you want to make this memory block
available for RDMA transfers.
• Line 122: The remote_open() routine creates or opens the remote
memory pool.
• Lines 126-127: The local memory pool is initialized here. It is
performed only once when the remote memory pool was just
created, so it does not contain any message.
• Line 130: A message from the remote memory pool is read to the
local memory here.
Chapter 18 remote persistent memory
