CARTA Backend
The backend component of CARTA
Loading...
Searching...
No Matches
Memory.h File Reference
#include <sys/mman.h>
#include <unistd.h>
#include <memory>
#include <string>
Include dependency graph for Memory.h:
This graph shows which files directly or indirectly include this file:

Classes

struct  AlignedDataDeleter
 Custom deleter for page-aligned data. More...
 

Typedefs

template<typename T >
using UniqueAlignedDataPtr = std::unique_ptr< T[], AlignedDataDeleter >
 Alias for a std::unique_ptr that manages a page-aligned dynamic array and has a custom deleter.
 

Functions

bool ExcludeFromCoreDump (void *address, size_t size)
 Mark the memory address range provided to be excluded from core dumps, if this is supported by the platform. The range must be page-aligned.
 
template<typename T >
UniqueAlignedDataPtr< T > MakeUniqueAlignedDataPtr (size_t size, bool exclude_from_core_dump=true)
 Create a UniqueAlignedDataPtr and optionally mark its data to be excluded from core dumps.
 

Typedef Documentation

◆ UniqueAlignedDataPtr

template<typename T >
using UniqueAlignedDataPtr = std::unique_ptr<T[], AlignedDataDeleter>

Alias for a std::unique_ptr that manages a page-aligned dynamic array and has a custom deleter.

Template Parameters
TThe type of the data in the array managed by the pointer.

Function Documentation

◆ ExcludeFromCoreDump()

bool ExcludeFromCoreDump ( void *  address,
size_t  size 
)

Mark the memory address range provided to be excluded from core dumps, if this is supported by the platform. The range must be page-aligned.

Parameters
addressThe starting address of the memory range, which must be page-aligned.
sizeThe size of the memory range, which must be an exact multiple of the page size.
Returns
Whether the address range was successfully marked.

Mark the memory address range provided to be excluded from core dumps, using the madvise system function, if this is supported by the platform (either MADV_DONTDUMP nor MADV_NOCORE must be defined). The address range must be page-aligned.

Note
If the functionality is unsupported or the address range is invalid, this function prints a warning message.
Here is the caller graph for this function:

◆ MakeUniqueAlignedDataPtr()

template<typename T >
UniqueAlignedDataPtr< T > MakeUniqueAlignedDataPtr ( size_t  size,
bool  exclude_from_core_dump = true 
)

Create a UniqueAlignedDataPtr and optionally mark its data to be excluded from core dumps.

This function allocates page-aligned memory using std::aligned_alloc. The array size is automatically converted to the raw memory size for the given data type and padded to a multiple of the page size. The custom deleter of the returned pointer automatically handles deallocation correctly when the pointer is destroyed.

Note
This function calls ExcludeFromCoreDump internally if exclude_from_core_dump is true, but ignores a failure result.
Template Parameters
TThe type of the data in the array managed by the pointer.
Parameters
sizeThe size of the array.
exclude_from_core_dumpWhether the data should be excluded from core dumps.
Returns
The constructed UniqueAlignedDataPtr.
Here is the call graph for this function: