162
Creating a Variable Size Heap
When PMEM_MAX_SIZE is set to zero, as shown below, allocations are satisfied as long as
the temporary file can grow. The maximum heap size growth is limited by the capacity of
the file system mounted under the PMEM_DIR argument.
memkind_create_pmem(PMEM_DIR, 0, &pmem_kind)
The arguments to memkind_create_pmem() are:
• PMEM_DIR is the directory where the temp file is created.
• PMEM_MAX_SIZE is 0.
• &pmem_kind is the address of a memkind data structure.
If the PMEM kind is created successfully, memkind_create_pmem() returns zero. On
failure, memkind_error_message() can be used to convert an error number returned by
memkind_create_pmem() to an error message string, as shown in the memkind_fatal()
routine in Listing 10-2.
Listing 10-4 shows how to create a PMEM kind with variable size.
Listing 10-4. Creating a PMEM kind with variable size
struct memkind *pmem_kind;
int err;
err = memkind_create_pmem("/daxfs",0,&pmem_kind);
if (err) {
memkind_fatal(err);
}
Detecting the Memory Kind
Memkind supports both automatic detection of the kind as well as a function to detect
the kind associated with a memory referenced by a pointer.
Automatic Kind Detection
Automatically detecting the kind of memory is supported to simplify code changes when
using libmemkind. Thus, the memkind library will automatically retrieve the kind of
memory pool the allocation was made from, so the heap management functions listed in
Table 10-1 can be called without specifying the kind.
Chapter 10 Volatile Use of persistent MeMory
Précédent

- 186/457

Suivant