\r\n

51Degrees Device Detection C/C++  4.4

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 2023 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 
34 #ifndef FIFTYONE_DEGREES_MEMORY_H_INCLUDED
35 #define FIFTYONE_DEGREES_MEMORY_H_INCLUDED
36 
37 #include <stdlib.h>
38 #include <stdbool.h>
39 #include "data.h"
40 #include "threading.h"
41 #include "tree.h"
42 #include "common.h"
43 
44 #ifdef _MSC_VER
45 #define FIFTYONE_DEGREES_CALL_CONV __cdecl
46 #else
47 #define FIFTYONE_DEGREES_CALL_CONV
48 #endif
49 
53 typedef struct fiftyone_degrees_memory_reader_t {
54  byte *startByte;
55  byte *current;
56  byte *lastByte;
57  long length;
59 
68  size_t advanceBy);
69 
75 EXTERNAL void* fiftyoneDegreesMemoryStandardMalloc(size_t __size);
76 
83 EXTERNAL void* fiftyoneDegreesMemoryTrackingMalloc(size_t __size);
84 
92  int alignment,
93  size_t __size);
94 
95 
105  int alignment,
106  size_t __size);
107 
114 EXTERNAL void fiftyoneDegreesMemoryTrackingFree(void *__ptr);
115 
122 EXTERNAL void fiftyoneDegreesMemoryTrackingFreeAligned(void* __ptr);
123 
128 EXTERNAL void fiftyoneDegreesMemoryStandardFree(void *__ptr);
129 
134 EXTERNAL void fiftyoneDegreesMemoryStandardFreeAligned(void *__ptr);
135 
143 EXTERNAL size_t fiftyoneDegreesMemoryTrackingGetMax();
144 
151 
157 EXTERNAL void fiftyoneDegreesMemoryTrackingReset();
158 
163 EXTERNAL void fiftyoneDegreesSetUpMemoryTracking();
164 
173 EXTERNAL size_t fiftyoneDegreesUnsetMemoryTracking();
174 
181 EXTERNAL_VAR void *(FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMalloc)(size_t __size);
182 
192 EXTERNAL_VAR void* (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMallocAligned)(
193  int alignment,
194  size_t __size);
195 
201 EXTERNAL_VAR void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFree)(void *__ptr);
202 
208 EXTERNAL_VAR void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFreeAligned)(void* __ptr);
209 
214 #endif
long length
Length of the file in bytes.
Definition: memory.h:57
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 fiftyoneDegreesUnsetMemoryTracking()
This function works in collaboration with fiftyoneDegreesSetUpMemoryTracking.
EXTERNAL_VAR void *(* fiftyoneDegreesMallocAligned)(int alignment, size_t __size)
Pointer to the method used to allocate aligned memory.
Definition: memory.h:192
EXTERNAL_VAR void(* fiftyoneDegreesFree)(void *__ptr)
Pointer to the method used to free memory.
Definition: memory.h:201
size_t fiftyoneDegreesMemoryTrackingGetMax()
Gets the maximum total number of bytes that have been allocated using the fiftyoneDegreesMemoryTracki...
Used to read data from memory in a similar manner to a file handle.
Definition: memory.h:53
byte * startByte
The first byte in memory.
Definition: memory.h:54
byte * current
The current byte being read from.
Definition: memory.h:55
void fiftyoneDegreesSetUpMemoryTracking()
Setup memory tracking by resetting memory tracking and setting all Malloc/Free function pointers to p...
void fiftyoneDegreesMemoryStandardFreeAligned(void *__ptr)
Frees memory using the standard aligned free method.
void fiftyoneDegreesMemoryTrackingFree(void *__ptr)
Frees memory allocated using the fiftyoneDegreesMemoryTrackingMalloc method, noting that it has now b...
void fiftyoneDegreesMemoryStandardFree(void *__ptr)
Frees memory using the standard free method.
size_t fiftyoneDegreesMemoryTrackingGetAllocated()
Gets the current number of bytes allocated using the tracking malloc and free methods.
EXTERNAL_VAR void *(* fiftyoneDegreesMalloc)(size_t __size)
Pointer to the method used to allocate memory.
Definition: memory.h:181
void * fiftyoneDegreesMemoryTrackingMallocAligned(int alignment, size_t __size)
Allocates aligned memory while keeping track of the memory which has been allocated using this method...
void * fiftyoneDegreesMemoryStandardMalloc(size_t __size)
Allocates memory using the standard malloc method.
byte * lastByte
The maximum byte that can be read from.
Definition: memory.h:56
void fiftyoneDegreesMemoryTrackingReset()
Resets the memory trackers keeping track of the data allocated using the fiftyoneDegreesMemoryTrackin...
void * fiftyoneDegreesMemoryStandardMallocAligned(int alignment, size_t __size)
Allocated aligned memory using the standard malloc method.
EXTERNAL_VAR void(* fiftyoneDegreesFreeAligned)(void *__ptr)
Pointer to the method used to free memory.
Definition: memory.h:208
bool fiftyoneDegreesMemoryAdvance(fiftyoneDegreesMemoryReader *reader, size_t advanceBy)
Used to read continuous memory checking for buffer over or under runs.