c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | List of all members
Cgu::GSliceFree< T > Class Template Reference
handles and smart pointers

A deleter functor for use as the second (Dealloc) template parameter of the SharedHandle, SharedLockHandle or ScopedHandle template classes, which calls glib's g_slice_free1(). More...

`#include <c++-gtk-utils/shared_handle.h>`

## Public Member Functions
void | operator() (T obj) noexcept

## Detailed Description

### template<class T>
class Cgu::GSliceFree< T >

A deleter functor for use as the second (Dealloc) template parameter of the SharedHandle, SharedLockHandle or ScopedHandle template classes, which calls glib's g_slice_free1().

This functor enables those classes to manage a memory block allocated using glib memory slices. The managed memory block to be deleted by the GSliceFree functor must have the same size as the size of the object for which the functor is instantiated by pointer, as for example as allocated with the g_slice_new, g_slice_new0 or g_slice_dup macros (in other words, the GSliceFree template parameter must match the argument passed to those macros): see the example below. Use GSliceFreeSize where it is necessary or more convenient to have the size of the block to be freed as the template parameter. Use GSliceDestroy where the memory holds a C++ object constructed in the memory by the global placement new expression.

The type of the template argument for the functor is a pointer to the managed type: it is the same as the first template argument of the relevant SharedHandle, SharedLockHandle or ScopedHandle object. For example:

using namespace Cgu;
SharedHandle<MyStruct*, GSliceFree<MyStruct*> > h(g_slice_new(MyStruct));
...

The availability of this functor is not dependent on the library having been installed with the --with-glib-memory-slices-compat or --with-glib-memory-slices-no-compat configuration option (see Memory allocation for further details of those options).

## Member Function Documentation

## ◆ operator()()

template<class T >

void Cgu::GSliceFree< T >::operator() | ( | T | obj | ) |
| inline noexcept

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

- shared_handle.h

Cgu
Definition: application.h:44
Cgu::SharedHandle
This is a generic class for managing the lifetime of objects allocated on freestore.
Definition: shared_handle.h:451