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

memory.h

1/* *********************************************************************
2 * This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 * Copyright 2026 51 Degrees Mobile Experts Limited, Davidson House,
4 * Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5 *
6 * This Original Work is licensed under the European Union Public Licence
7 * (EUPL) v.1.2 and is subject to its terms as set out below.
8 *
9 * If a copy of the EUPL was not distributed with this file, You can obtain
10 * one at https://opensource.org/licenses/EUPL-1.2.
11 *
12 * The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 * amended by the European Commission) shall be deemed incompatible for
14 * the purposes of the Work and the provisions of the compatibility
15 * clause in Article 5 of the EUPL shall not apply.
16 *
17 * If using the Work as, or as part of, a network application, by
18 * including the attribution notice(s) required under Article 5 of the EUPL
19 * in the end user terms of the application under an appropriate heading,
20 * such notice(s) shall fulfill the requirements of that article.
21 * ********************************************************************* */
22
33
34#ifndef FIFTYONE_DEGREES_MEMORY_H_INCLUDED
35#define FIFTYONE_DEGREES_MEMORY_H_INCLUDED
36
37#ifdef FIFTYONE_DEGREES_IPI_SYMBOLS
38#include "ipiSymbols.h"
39#endif
40
41#include <stdlib.h>
42#include <stdbool.h>
43#include "data.h"
44#include "threading.h"
45#include "tree.h"
46#include "common.h"
47#include "fileOffset.h"
48
49#ifdef _MSC_VER
50#define FIFTYONE_DEGREES_CALL_CONV __cdecl
51#else
52#define FIFTYONE_DEGREES_CALL_CONV
53#endif
54
58typedef struct fiftyone_degrees_memory_reader_t {
59 byte *startByte;
60 byte *current;
61 byte *lastByte;
64
73 size_t advanceBy);
74
80EXTERNAL void* fiftyoneDegreesMemoryStandardMalloc(size_t __size);
81
88EXTERNAL void* fiftyoneDegreesMemoryTrackingMalloc(size_t __size);
89
97 int alignment,
98 size_t __size);
99
100
110 int alignment,
111 size_t __size);
112
119EXTERNAL void fiftyoneDegreesMemoryTrackingFree(void *__ptr);
120
128
133EXTERNAL void fiftyoneDegreesMemoryStandardFree(void *__ptr);
134
140
149
156
163
169
179
186EXTERNAL_VAR void *(FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMalloc)(size_t __size);
187
197EXTERNAL_VAR void* (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMallocAligned)(
198 int alignment,
199 size_t __size);
200
206EXTERNAL_VAR void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFree)(void *__ptr);
207
213EXTERNAL_VAR void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFreeAligned)(void* __ptr);
214
218
219#endif
long fiftyoneDegreesFileOffset
Type for file offset in API.
Definition fileOffset.h:73
void fiftyoneDegreesMemoryStandardFree(void *__ptr)
Frees memory using the standard free method.
void * fiftyoneDegreesMemoryTrackingMallocAligned(int alignment, size_t __size)
Allocates aligned memory while keeping track of the memory which has been allocated using this method...
void fiftyoneDegreesMemoryTrackingFree(void *__ptr)
Frees memory allocated using the fiftyoneDegreesMemoryTrackingMalloc method, noting that it has now b...
size_t fiftyoneDegreesMemoryTrackingGetAllocated()
Gets the current number of bytes allocated using the tracking malloc and free methods.
void * fiftyoneDegreesMemoryStandardMallocAligned(int alignment, size_t __size)
Allocated aligned memory using the standard malloc method.
void * fiftyoneDegreesMemoryStandardMalloc(size_t __size)
Allocates memory using the standard malloc method.
size_t fiftyoneDegreesUnsetMemoryTracking()
This function works in collaboration with fiftyoneDegreesSetUpMemoryTracking.
bool fiftyoneDegreesMemoryAdvance(fiftyoneDegreesMemoryReader *reader, size_t advanceBy)
Used to read continuous memory checking for buffer over or under runs.
void fiftyoneDegreesMemoryTrackingReset()
Resets the memory trackers keeping track of the data allocated using the fiftyoneDegreesMemoryTrackin...
void fiftyoneDegreesSetUpMemoryTracking()
Setup memory tracking by resetting memory tracking and setting all Malloc/Free function pointers to p...
void fiftyoneDegreesMemoryTrackingFreeAligned(void *__ptr)
Frees memory allocated using the fiftyoneDegreesMemoryTrackingMallocAligned method,...
void * fiftyoneDegreesMemoryTrackingMalloc(size_t __size)
Allocates memory while keeping track of the memory which has been allocated using this method since c...
size_t fiftyoneDegreesMemoryTrackingGetMax()
Gets the maximum total number of bytes that have been allocated using the fiftyoneDegreesMemoryTracki...
void fiftyoneDegreesMemoryStandardFreeAligned(void *__ptr)
Frees memory using the standard aligned free method.
Used to read data from memory in a similar manner to a file handle.
Definition memory.h:58
byte * lastByte
The maximum byte that can be read from.
Definition memory.h:61
byte * startByte
The first byte in memory.
Definition memory.h:59
byte * current
The current byte being read from.
Definition memory.h:60
fiftyoneDegreesFileOffset length
Length of the file in bytes.
Definition memory.h:62