164
78 /* do some allocations... */
79 buf0 = memkind_malloc(pmem_kind, 1000);
80 buf1 = memkind_malloc(MEMKIND_DEFAULT, 1000);
81
82 /* look up the kind of an allocation */
83 if (memkind_detect_kind(buf0) == MEMKIND_DEFAULT) {
84
printf("buf0 is DRAM\n");
85 } else {
86
printf("buf0 is pmem\n");
87 }
Destroying Kind Objects
Use the memkind_destroy_kind() function, shown below, to delete the kind object that
was previously created using the memkind_create_pmem() or memkind_create_pmem_
with_config() function.
int memkind_destroy_kind(memkind_t kind);
Using the same pmem_detect_kind.c code from Listing 10-5, Listing 10-6 shows how
the kind is destroyed before the program exits.
Listing 10-6. Destroying a kind object
89
err = memkind_destroy_kind(pmem_kind);
90
if (err) {
91
memkind_fatal(err);
92
}
When the kind returned by memkind_create_pmem() or memkind_create_pmem_with_
config() is successfully destroyed, all the allocated memory for the kind object is freed.
Heap Management API
The heap management functions described in this section have an interface modeled on
the ISO C standard API, with an additional “kind” parameter to specify the memory type
used for allocation.
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 188/457

Suivant