51Degrees Device Detection C/C++  4.1

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 2019 51 Degrees Mobile Experts Limited, 5 Charlotte Close,
4  * Caversham, Reading, Berkshire, United Kingdom RG4 7BY.
5  *
6  * This Original Work is licensed under the European Union Public Licence (EUPL)
7  * 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 
43 #ifdef __cplusplus
44 #define EXTERNAL extern "C"
45 #else
46 #define EXTERNAL
47 #endif
48 
49 #ifdef _MSC_VER
50 #define FIFTYONE_DEGREES_CALL_CONV __cdecl
51 #else
52 #define FIFTYONE_DEGREES_CALL_CONV
53 #endif
54 
58 typedef struct fiftyone_degrees_memory_reader_t {
59  byte *startByte;
60  byte *current;
61  byte *lastByte;
62  long length;
64 
73  size_t advanceBy);
74 
80 EXTERNAL void* fiftyoneDegreesMemoryStandardMalloc(size_t __size);
81 
88 EXTERNAL void* fiftyoneDegreesMemoryTrackingMalloc(size_t __size);
89 
97  int alignment,
98  size_t __size);
99 
100 
110  int alignment,
111  size_t __size);
112 
119 EXTERNAL void fiftyoneDegreesMemoryTrackingFree(void *__ptr);
120 
127 EXTERNAL void fiftyoneDegreesMemoryTrackingFreeAligned(void* __ptr);
128 
133 EXTERNAL void fiftyoneDegreesMemoryStandardFree(void *__ptr);
134 
139 EXTERNAL void fiftyoneDegreesMemoryStandardFreeAligned(void *__ptr);
140 
148 EXTERNAL size_t fiftyoneDegreesMemoryTrackingGetMax();
149 
156 
162 EXTERNAL void fiftyoneDegreesMemoryTrackingReset();
163 
170 EXTERNAL void *(FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMalloc)(size_t __size);
171 
181 EXTERNAL void* (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesMallocAligned)(
182  int alignment,
183  size_t __size);
184 
190 EXTERNAL void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFree)(void *__ptr);
191 
197 EXTERNAL void (FIFTYONE_DEGREES_CALL_CONV *fiftyoneDegreesFreeAligned)(void* __ptr);
198 
203 #endif
long length
Length of the file in bytes.
Definition: memory.h:62
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...
void(* fiftyoneDegreesFreeAligned)(void *__ptr)
Pointer to the method used to free memory.
Definition: memory.h:197
void *(* fiftyoneDegreesMallocAligned)(int alignment, size_t __size)
Pointer to the method used to allocate aligned memory.
Definition: memory.h:181
size_t fiftyoneDegreesMemoryTrackingGetMax()
Gets the maximum total number of bytes that have been allocated using the fiftyoneDegreesMemoryTracki...
void(* fiftyoneDegreesFree)(void *__ptr)
Pointer to the method used to free memory.
Definition: memory.h:190
void *(* fiftyoneDegreesMalloc)(size_t __size)
Pointer to the method used to allocate memory.
Definition: memory.h:170
Used to read data from memory in a similar manner to a file handle.
Definition: memory.h:58
byte * startByte
The first byte in memory.
Definition: memory.h:59
byte * current
The current byte being read from.
Definition: memory.h:60
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.
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:61
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.
bool fiftyoneDegreesMemoryAdvance(fiftyoneDegreesMemoryReader *reader, size_t advanceBy)
Used to read continuous memory checking for buffer over or under runs.