MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
legato_memory.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
3 *
4 * Subject to your compliance with these terms, you may use Microchip software
5 * and any derivatives exclusively with Microchip products. It is your
6 * responsibility to comply with third party license terms applicable to your
7 * use of third party software (including open source software) that may
8 * accompany Microchip software.
9 *
10 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
11 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
12 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
13 * PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
16 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
17 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
18 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
19 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
20 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
21 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
22 *******************************************************************************/
23 /*******************************************************************************
24  Module for Microchip Graphics Library - Legato User Interface Library
25 
26  Company:
27  Microchip Technology Inc.
28 
29  File Name:
30  legato_memory.h
31 
32  Summary:
33  File containing various memory-related constructs.
34 *******************************************************************************/
41 #ifndef LEGATO_MEMORY_H
42 #define LEGATO_MEMORY_H
43 
45 
46 #if LE_MEMORY_MANAGER_ENABLE == 1
47 
48 #define LE_FIXED_HEAP_COUNT 7
49 
53 typedef struct leVariableHeapUsageReport
54 {
55  size_t size;
56  size_t maxUsage;
57  size_t used;
58 } leVariableHeapUsageReport;
59 
63 enum leFixedHeapSize
64 {
65  FH_16,
66  FH_32,
67  FH_64,
68  FH_128,
69  FH_196,
70  FH_256
71 };
72 
76 typedef struct leFixedHeapUsageReport
77 {
78  size_t logicalSize;
79  size_t numElements;
80  size_t currentCapacity;
81  size_t maxUsage;
82 } leFixedHeapUsageReport;
83 
87 typedef struct leMemoryStatusReport
88 {
89  leVariableHeapUsageReport variableHeapReport;
90  leFixedHeapUsageReport fixedHeapReport[LE_FIXED_HEAP_COUNT - 1];
91 } leMemoryStatusReport;
92 
102 leResult leMemory_Init(void);
103 
104 #if LE_USE_DEBUG_ALLOCATOR == 1
105 #define LE_MALLOC(size) leMalloc(size, __LINE__, __FUNCTION__, __FILE__)
106 #define LE_REALLOC(ptr, size) leRealloc(ptr, size, __LINE__, __FUNCTION__, __FILE__)
107 #else
108 #define LE_MALLOC(size) leMalloc(size)
109 #define LE_REALLOC(ptr, size) leRealloc(ptr, size)
110 #endif
111 
112 #define LE_FREE(ptr) leFree(ptr)
113 
114 #if LE_USE_DEBUG_ALLOCATOR == 1
115 
124 void* leMalloc(size_t size,
125  size_t line,
126  const char* func,
127  const char* file);
128 
142 void* leRealloc(void* ptr,
143  size_t size,
144  size_t line,
145  const char* func,
146  const char* file);
147 
157 void leFree(void* ptr);
158 #else
159 
168 void* leMalloc(size_t size);
169 
180 void* leRealloc(void* ptr,
181  size_t size);
182 
193 void leFree(void* ptr);
194 #endif
195 
205 void leMemoryGetUsageReport(leMemoryStatusReport* rpt);
206 
207 #ifdef _WIN32
208 void leMemoryDumpAllocations(void);
209 #endif
210 
220 leResult leMemoryValidateHeaps(void);
221 
222 #else
223 
224 #include <stdlib.h>
225 
226 #define LE_MALLOC(size) malloc(size)
227 #define LE_REALLOC(ptr, size) realloc(ptr, size)
228 #define LE_FREE(ptr) free(ptr)
229 #endif // LE_MEMORY_MANAGER_ENABLE
230 
231 #endif /* LEGATO_MEMORY_H */
Common macros and definitions used by Legato.
leResult
This enum represents function call results.
Definition: legato_common.h:123