mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-22 17:12:55 +08:00
45 lines
745 B
C
45 lines
745 B
C
|
#include "dataMemory.h"
|
||
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
PikaMemInfo pikaMemInfo = {0};
|
||
|
|
||
|
void *pikaMalloc(uint32_t size)
|
||
|
{
|
||
|
pikaMemInfo.heapUsed += size;
|
||
|
if (pikaMemInfo.heapUsedMax < pikaMemInfo.heapUsed)
|
||
|
{
|
||
|
pikaMemInfo.heapUsedMax = pikaMemInfo.heapUsed;
|
||
|
}
|
||
|
void *mem = malloc(size);
|
||
|
if (NULL == mem)
|
||
|
{
|
||
|
printf("[error]: No heap space!\r\n");
|
||
|
while (1)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
return mem;
|
||
|
}
|
||
|
|
||
|
void pikaFree(void *mem, uint32_t size)
|
||
|
{
|
||
|
free(mem);
|
||
|
pikaMemInfo.heapUsed -= size;
|
||
|
}
|
||
|
|
||
|
uint16_t pikaMemNow(void)
|
||
|
{
|
||
|
return pikaMemInfo.heapUsed;
|
||
|
}
|
||
|
|
||
|
uint16_t pikaMemMax(void)
|
||
|
{
|
||
|
return pikaMemInfo.heapUsedMax;
|
||
|
}
|
||
|
|
||
|
void pikaMemMaxReset(void)
|
||
|
{
|
||
|
pikaMemInfo.heapUsedMax = 0;
|
||
|
}
|