\r\n

51Degrees Device Detection C/C++  4.4

A device detection library that is used natively or by 51Degrees products

Memory

Detailed Description

Utility methods used to handle common memory operations such as allocating memory and freeing it, or reading through continuous memory checking for buffer over or under runs.

Collaboration diagram for Memory:

Structs

struct  fiftyoneDegreesMemoryReader
Used to read data from memory in a similar manner to a file handle. More...

Functions

bool  fiftyoneDegreesMemoryAdvance (fiftyoneDegreesMemoryReader *reader, size_t advanceBy)
Used to read continuous memory checking for buffer over or under runs. More...
void *  fiftyoneDegreesMemoryStandardMalloc (size_t __size)
Allocates memory using the standard malloc method. More...
void *  fiftyoneDegreesMemoryTrackingMalloc (size_t __size)
Allocates memory while keeping track of the memory which has been allocated using this method since calling fiftyoneDegreesMemoryTrackingReset. More...
void *  fiftyoneDegreesMemoryStandardMallocAligned (int alignment, size_t __size)
Allocated aligned memory using the standard malloc method. More...
void *  fiftyoneDegreesMemoryTrackingMallocAligned (int alignment, size_t __size)
Allocates aligned memory while keeping track of the memory which has been allocated using this method since calling fiftyoneDegreesMemoryTrackingReset. More...
void  fiftyoneDegreesMemoryTrackingFree (void *__ptr)
Frees memory allocated using the fiftyoneDegreesMemoryTrackingMalloc method, noting that it has now been freed and does not contribute to the current total. More...
void  fiftyoneDegreesMemoryTrackingFreeAligned (void *__ptr)
Frees memory allocated using the fiftyoneDegreesMemoryTrackingMallocAligned method, noting that it has now been freed and does not contribute to the current total. More...
void  fiftyoneDegreesMemoryStandardFree (void *__ptr)
Frees memory using the standard free method. More...
void  fiftyoneDegreesMemoryStandardFreeAligned (void *__ptr)
Frees memory using the standard aligned free method. More...
size_t  fiftyoneDegreesMemoryTrackingGetMax ()
Gets the maximum total number of bytes that have been allocated using the fiftyoneDegreesMemoryTrackingMalloc method. More...
size_t  fiftyoneDegreesMemoryTrackingGetAllocated ()
Gets the current number of bytes allocated using the tracking malloc and free methods. More...
void  fiftyoneDegreesMemoryTrackingReset ()
Resets the memory trackers keeping track of the data allocated using the fiftyoneDegreesMemoryTrackingMalloc method. More...
void  fiftyoneDegreesSetUpMemoryTracking ()
Setup memory tracking by resetting memory tracking and setting all Malloc/Free function pointers to pointer to TrackingMalloc/Free functions.
size_t  fiftyoneDegreesUnsetMemoryTracking ()
This function works in collaboration with fiftyoneDegreesSetUpMemoryTracking. More...

Variables

EXTERNAL_VAR void *(*  fiftyoneDegreesMalloc )(size_t __size)
Pointer to the method used to allocate memory. More...
EXTERNAL_VAR void *(*  fiftyoneDegreesMallocAligned )(int alignment, size_t __size)
Pointer to the method used to allocate aligned memory. More...
EXTERNAL_VAR void(*  fiftyoneDegreesFree )(void *__ptr)
Pointer to the method used to free memory. More...
EXTERNAL_VAR void(*  fiftyoneDegreesFreeAligned )(void *__ptr)
Pointer to the method used to free memory. More...

Function Documentation

◆ fiftyoneDegreesMemoryAdvance()

bool fiftyoneDegreesMemoryAdvance ( fiftyoneDegreesMemoryReader *   reader,
size_t   advanceBy  
)

Used to read continuous memory checking for buffer over or under runs.

Parameters
reader - structure used to check for last byte
advanceBy - number of bytes to advance current by
Returns
true if the advance succeeded, otherwise false

◆ fiftyoneDegreesMemoryStandardFree()

void fiftyoneDegreesMemoryStandardFree ( void *   __ptr )

Frees memory using the standard free method.

Parameters
__ptr - data to free

◆ fiftyoneDegreesMemoryStandardFreeAligned()

void fiftyoneDegreesMemoryStandardFreeAligned ( void *   __ptr )

Frees memory using the standard aligned free method.

Parameters
__ptr - data to free

◆ fiftyoneDegreesMemoryStandardMalloc()

void* fiftyoneDegreesMemoryStandardMalloc ( size_t   __size )

Allocates memory using the standard malloc method.

Parameters
__size - number of bytes to allocate
Returns
pointer to allocated memory or NULL

◆ fiftyoneDegreesMemoryStandardMallocAligned()

void* fiftyoneDegreesMemoryStandardMallocAligned ( int   alignment,
size_t   __size  
)

Allocated aligned memory using the standard malloc method.

Parameters
alignment - byte boundary to align the allocation to e.g. 16
__size - number of bytes to allocate
Returns
pointer to allocation memory or NULL

◆ fiftyoneDegreesMemoryTrackingFree()

void fiftyoneDegreesMemoryTrackingFree ( void *   __ptr )

Frees memory allocated using the fiftyoneDegreesMemoryTrackingMalloc method, noting that it has now been freed and does not contribute to the current total.

Parameters
__ptr - data to free

◆ fiftyoneDegreesMemoryTrackingFreeAligned()

void fiftyoneDegreesMemoryTrackingFreeAligned ( void *   __ptr )

Frees memory allocated using the fiftyoneDegreesMemoryTrackingMallocAligned method, noting that it has now been freed and does not contribute to the current total.

Parameters
__ptr - data to free

◆ fiftyoneDegreesMemoryTrackingGetAllocated()

size_t fiftyoneDegreesMemoryTrackingGetAllocated ( )

Gets the current number of bytes allocated using the tracking malloc and free methods.

Returns
total bytes currently allocated

◆ fiftyoneDegreesMemoryTrackingGetMax()

size_t fiftyoneDegreesMemoryTrackingGetMax ( )

Gets the maximum total number of bytes that have been allocated using the fiftyoneDegreesMemoryTrackingMalloc method.

NOTE: this is the total at any point in time since the fiftyoneDegreesMemoryTrackingReset method was called, NOT the total allocated in a single allocation.

Returns
maximum total allocation

◆ fiftyoneDegreesMemoryTrackingMalloc()

void* fiftyoneDegreesMemoryTrackingMalloc ( size_t   __size )

Allocates memory while keeping track of the memory which has been allocated using this method since calling fiftyoneDegreesMemoryTrackingReset.

Parameters
__size - number of bytes to allocate
Returns
pointer to allocated memory or NULL

◆ fiftyoneDegreesMemoryTrackingMallocAligned()

void* fiftyoneDegreesMemoryTrackingMallocAligned ( int   alignment,
size_t   __size  
)

Allocates aligned memory while keeping track of the memory which has been allocated using this method since calling fiftyoneDegreesMemoryTrackingReset.

Parameters
alignment - byte boundary to align the allocation to e.g. 16
__size - number of bytes to allocate
Returns
pointer to allocation memory or NULL

◆ fiftyoneDegreesMemoryTrackingReset()

void fiftyoneDegreesMemoryTrackingReset ( )

Resets the memory trackers keeping track of the data allocated using the fiftyoneDegreesMemoryTrackingMalloc method.

This should always be called before tracking memory allocations.

◆ fiftyoneDegreesUnsetMemoryTracking()

size_t fiftyoneDegreesUnsetMemoryTracking ( )

This function works in collaboration with fiftyoneDegreesSetUpMemoryTracking.

Check if all tracking memory has been freed. Unset memory tracking by setting all Malloc/Free function pointer to standard Malloc/Free functions. Then, reset memory tracking.

Returns
0 if all freed, non 0 if there are memory left unfreed. The returned value is the size of allocated memory left unfreed.

Variable Documentation

◆ fiftyoneDegreesFreeAligned

EXTERNAL_VAR void( * fiftyoneDegreesFreeAligned) (void *__ptr)

Pointer to the method used to free memory.

By default this maps to fiftyoneDegreesMemoryStandardFreeAligned which calls the standard library free.

Parameters
__ptr - pointer to free

◆ fiftyoneDegreesMalloc

EXTERNAL_VAR void*( * fiftyoneDegreesMalloc) (size_t __size)

Pointer to the method used to allocate memory.

By default this maps to fiftyoneDegreesMemoryStandardMalloc which calls the standard library malloc.

Parameters
__size - to allocate
Returns
pointer to allocated memory or NULL

◆ fiftyoneDegreesMallocAligned

EXTERNAL_VAR void*( * fiftyoneDegreesMallocAligned) (int alignment, size_t __size)

Pointer to the method used to allocate aligned memory.

By default this maps to fiftyoneDegreesMemoryStandardMallocAligned which calls the standard library malloc, allocating slightly more that requested, then ensures the pointer is aligned to a boundary.

Parameters
alignment - byte boundary to align the allocation to e.g. 16
__size - to allocate
Returns
pointer to allocated memory or NULL