163
The memkind library internally tracks the kind of a given object from the allocator
metadata. However, to get this information, some of the operations may need to
acquire a lock to prevent accesses from other threads, which may negatively affect the
performance in a multithreaded environment.
Memory Kind Detection
Memkind also provides the memkind_detect_kind() function, shown below, to query
and return the kind of memory referenced by the pointer passed into the function.
If the input pointer argument is NULL, the function returns NULL. The input pointer
argument passed into memkind_detect_kind() must have been returned by a previous
call to memkind_malloc(), memkind_calloc(), memkind_realloc(), or memkind_posix_
memalign().
memkind_t memkind_detect_kind(void *ptr)
Similar to the automatic detection approach, this function has nontrivial
performance overhead. Listing 10-5 shows how to detect the kind type.
Listing 10-5. pmem_detect_kind.c – how to automatically detect the ‘kind’ type
73 err = memkind_create_pmem(path, 0, &pmem_kind);
74 if (err) {
75
memkind_fatal(err);
76 }
77
Table 10-1. Automatic kind detection functions and their equivalent specified
kind functions and operations
Operation
Memkind API with Kind
Memkind API Using Automatic Detection
free
memkind_free(kind, ptr)
memkind_free(nUll, ptr)
realloc
memkind_realloc(kind, ptr, size) memkind_realloc(nUll, ptr, size)
Get size of allocated
memory
memkind_malloc_usable_
size(kind, ptr)
memkind_malloc_usable_size(nUll, ptr)
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 187/457

Suivant