\r\n

51Degrees Device Detection C/C++  4.5

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 #include "fileOffset.h"
44 
45 #ifdef _MSC_VER
46 #define FIFTYONE_DEGREES_CALL_CONV __cdecl
47 #else
48 #define FIFTYONE_DEGREES_CALL_CONV
49 #endif
50 
54 typedef struct fiftyone_degrees_memory_reader_t {
55  byte *startByte;
56  byte *current;
57  byte *lastByte;
60 
69  size_t advanceBy);
70 
76 EXTERNAL void* fiftyoneDegreesMemoryStandardMalloc(size_t __size);
77 
84 EXTERNAL void* fiftyoneDegreesMemoryTrackingMalloc(size_t __size);
85 
93  int alignment,
94  size_t __size);
95 
96 
106  int alignment,
107  size_t __size);
108 
115 EXTERNAL void fiftyoneDegreesMemoryTrackingFree(void *__ptr);
116 
123 EXTERNAL void fiftyoneDegreesMemoryTrackingFreeAligned(void* __ptr);
124 
129 EXTERNAL void fiftyoneDegreesMemoryStandardFree(void *__ptr);
130 
135 EXTERNAL void fiftyoneDegreesMemoryStandardFreeAligned(void *__ptr);
136 
144 EXTERNAL size_t fiftyoneDegreesMemoryTrackingGetMax();
145 
152 
158 EXTERNAL void fiftyoneDegreesMemoryTrackingReset();
159 
164 EXTERNAL void fiftyoneDegreesSetUpMemoryTracking();
165 
174 EXTERNAL size_t fiftyoneDegreesUnsetMemoryTracking();
175 
182 EXTERNAL_VAR void *(FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMalloc)(size_t __size);
183 
193 EXTERNAL_VAR void* (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMallocAligned)(
194  int alignment,
195  size_t __size);
196 
202 EXTERNAL_VAR void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFree)(void *__ptr);
203 
209 EXTERNAL_VAR void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFreeAligned)(void* __ptr);
210 
215 #endif
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:193
EXTERNAL_VAR void(* fiftyoneDegreesFree)(void *__ptr)
Pointer to the method used to free memory.
Definition: memory.h:202
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:54
byte * startByte
The first byte in memory.
Definition: memory.h:55
byte * current
The current byte being read from.
Definition: memory.h:56
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...
fiftyoneDegreesFileOffset length
Length of the file in bytes.
Definition: memory.h:58
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:182
void * fiftyoneDegreesMemoryTrackingMallocAligned(int alignment, size_t __size)
Allocates aligned memory while keeping track of the memory which has been allocated using this method...
long fiftyoneDegreesFileOffset
Type for file offset in API.
Definition: fileOffset.h:69
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:57
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:209
bool fiftyoneDegreesMemoryAdvance(fiftyoneDegreesMemoryReader *reader, size_t advanceBy)
Used to read continuous memory checking for buffer over or under runs.