366
67
static inline void
68
write_hello_str(struct hello_t *hello, enum lang_t lang)
69
{
70
hello->lang = lang;
71
strncpy(hello->str, hello_str[hello->lang], STR_SIZE);
72
}
104
int
105
main(int argc, char *argv[])
106
{
107
/* for this example, assume 32MiB pool */
108
size_t pool_size = 32 * 1024 * 1024;
109
void *pool = NULL;
110
int created;
111
112
/* allocate a page size aligned local memory pool */
113
long pagesize = sysconf(_SC_PAGESIZE);
114
assert(pagesize >= 0);
115
int ret = posix_memalign(&pool, pagesize, pool_size);
116
assert(ret == 0 && pool != NULL);
117
118
/* skip to the beginning of the message */
119
size_t hello_off = 4096; /* rpmem header size */
120
struct hello_t *hello = (struct hello_t *)(pool + hello_off);
121
122
RPMEMpool *rpp = remote_open("target", "pool.set", pool,
pool_size,
123
&created);
124
if (created) {
125
/* reset local memory pool */
126
memset(pool, 0, pool_size);
127
write_hello_str(hello, en);
128
} else {
129
/* read message from the remote pool */
130
ret = rpmem_read(rpp, hello, hello_off, sizeof(*hello), 0);
131
assert(ret == 0);
Chapter 18 remote persistent memory
67
static inline void
68
write_hello_str(struct hello_t *hello, enum lang_t lang)
69
{
70
hello->lang = lang;
71
strncpy(hello->str, hello_str[hello->lang], STR_SIZE);
72
}
104
int
105
main(int argc, char *argv[])
106
{
107
/* for this example, assume 32MiB pool */
108
size_t pool_size = 32 * 1024 * 1024;
109
void *pool = NULL;
110
int created;
111
112
/* allocate a page size aligned local memory pool */
113
long pagesize = sysconf(_SC_PAGESIZE);
114
assert(pagesize >= 0);
115
int ret = posix_memalign(&pool, pagesize, pool_size);
116
assert(ret == 0 && pool != NULL);
117
118
/* skip to the beginning of the message */
119
size_t hello_off = 4096; /* rpmem header size */
120
struct hello_t *hello = (struct hello_t *)(pool + hello_off);
121
122
RPMEMpool *rpp = remote_open("target", "pool.set", pool,
pool_size,
123
&created);
124
if (created) {
125
/* reset local memory pool */
126
memset(pool, 0, pool_size);
127
write_hello_str(hello, en);
128
} else {
129
/* read message from the remote pool */
130
ret = rpmem_read(rpp, hello, hello_off, sizeof(*hello), 0);
131
assert(ret == 0);
Chapter 18 remote persistent memory
