161
memkind_error_message(err, error_message,
MEMKIND_ERROR_MESSAGE_SIZE);
fprintf(stderr, "%s\n", error_message);
exit(1);
}
/* ... in main() ... */
#define PMEM_MAX_SIZE (1024 * 1024 * 32)
struct memkind *pmem_kind;
int err;
// Create PMEM memory pool with specific size
err = memkind_create_pmem("/daxfs",PMEM_MAX_SIZE, &pmem_kind);
if (err) {
memkind_fatal(err);
}
You can also create a heap with a specific configuration using the function memkind_
create_pmem_with_config(). This function uses a memkind_config structure with
optional parameters such as size, file path, and memory usage policy. Listing 10-3
shows how to build a test_cfg using memkind_config_new(), then passing that
configuration to memkind_create_pmem_with_config() to create a PMEM kind. We use
the same path and size parameters from the Listing 10-2 example for comparison.
Listing 10-3. Creating PMEM kind with configuration
struct memkind_config *test_cfg = memkind_config_new();
memkind_config_set_path(test_cfg, "/daxfs");
memkind_config_set_size(test_cfg, 1024 * 1024 * 32);
memkind_config_set_memory_usage_policy(test_cfg, MEMKIND_MEM_USAGE_POLICY_
CONSERVATIVE);
// create a PMEM partition with specific configuration
err = memkind_create_pmem_with_config(test_cfg, &pmem_kind);
if (err) {
memkind_fatal(err);
}
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 185/457

Suivant