PMDK C++ bindings  1.13.0-git23.gf49772ac
This is the C++ bindings documentation for PMDK's libpmemobj.
Public Member Functions | List of all members
pmem::obj::experimental::basic_inline_string< CharT, Traits > Class Template Reference

This class serves similar purpose to pmem::obj::string, but keeps the data within the same allocation as inline_string itself. More...

#include <libpmemobj++/experimental/inline_string.hpp>

Inherits pmem::obj::experimental::basic_inline_string_base< CharT, Traits >.

Public Member Functions

 basic_inline_string (basic_string_view< CharT, Traits > v)
 
 basic_inline_string (size_type capacity)
 
 basic_inline_string (const basic_inline_string &rhs)
 

Detailed Description

template<typename CharT, typename Traits = std::char_traits<CharT>>
class pmem::obj::experimental::basic_inline_string< CharT, Traits >

This class serves similar purpose to pmem::obj::string, but keeps the data within the same allocation as inline_string itself.

It can be kept only on pmem.

The data is always kept right after the inline_string structure. It means that creating an object of inline_string must be done as follows:

  1. Allocate memory of sizeof(inline_string) + size of the characters string + sizeof('\0')
  2. Use emplace new() to create inline_string

Example:

struct Object {
Object(int x, const char *s) : x(x), s(s)
{
}
int x;
/* Using inline_string instead of pmem::obj::string reduces number of
* allocations and dereferences which cost much more than on DRAM.
*/
};
struct root {
};
void
create_and_print_object(pmem::obj::pool<root> pop)
{
auto r = pop.root();
/* String was already allocated in a previous app run. */
if (r->o)
return;
auto value = "example";
/* There must be space for the Object itself and "example"
* string. */
auto req_capacity =
sizeof(Object) + strlen(value) + sizeof('\0');
r->o = static_cast<pmem::obj::persistent_ptr<Object>>(
a.allocate(req_capacity));
new (r->o.get()) Object(1, value);
});
std::cout << r->o->s.data() << std::endl;
}
void
assign_and_print_object(pmem::obj::pool<root> pop)
{
auto r = pop.root();
auto new_value = "some new, longer value";
if (r->o->s.capacity() >= strlen(new_value)) {
/* If there is enough capacity, we can assign the new value. */
r->o->s.assign(new_value);
} else {
/* Otherwise we have to reallocate the whole object. */
auto ptr =
a.allocate(sizeof(Object) +
strlen(new_value) + 1));
new (ptr.get()) Object(r->o->x, new_value);
pmem::obj::delete_persistent<Object>(r->o);
r->o = ptr;
});
}
std::cout << r->o->s.data() << std::endl;
}
(EXPERIMENTAL) Encapsulates the information about the persistent memory allocation model using PMDK's...
Definition: allocator.hpp:446
static void run(obj::pool_base &pool, std::function< void()> tx, Locks &... locks)
Execute a closure-like transaction and lock locks.
Definition: transaction.hpp:694
This class serves similar purpose to pmem::obj::string, but keeps the data within the same allocation...
Definition: inline_string.hpp:154
Persistent pointer class.
Definition: persistent_ptr.hpp:152
PMEMobj pool class.
Definition: pool.hpp:482
persistent_ptr< T > root()
Retrieves pool's root object.
Definition: pool.hpp:644
pointer allocate(size_type cnt, const_void_pointer=0)
Allocate storage for cnt objects of type T.
Definition: allocator.hpp:242

Constructor & Destructor Documentation

◆ basic_inline_string() [1/3]

template<typename CharT , typename Traits = std::char_traits<CharT>>
pmem::obj::experimental::basic_inline_string< CharT, Traits >::basic_inline_string ( basic_string_view< CharT, Traits >  v)
inline
Exceptions
pool_errorif inline string is not on pmem.

◆ basic_inline_string() [2/3]

template<typename CharT , typename Traits = std::char_traits<CharT>>
pmem::obj::experimental::basic_inline_string< CharT, Traits >::basic_inline_string ( size_type  capacity)
inline
Exceptions
pool_errorif inline string is not on pmem.

◆ basic_inline_string() [3/3]

template<typename CharT , typename Traits = std::char_traits<CharT>>
pmem::obj::experimental::basic_inline_string< CharT, Traits >::basic_inline_string ( const basic_inline_string< CharT, Traits > &  rhs)
inline
Exceptions
pool_errorif inline string is not on pmem.

The documentation for this class was generated from the following file: