/
vTech
/
FcApps
Обзор
Документация
Войти
/
vTech
/
FcApps
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
FcLibs/FcUI/src/FcUI_Memory.h
81 строка
2 KB
vTech
alpha_00
03 дек 2025, 17:45
03 дек 2025, 17:45
ab8382d
Код
Авторство
О чём код?
#ifndef _FCUI_MEMORY_H_ #define _FCUI_MEMORY_H_ #include "FcUI_Setting.h" #include "FcUI_Error.h" typedef struct _FcUI_Memory_t { size_t mSize; size_t mSizePadding; uint8_t mData[sizeof(double)]; }FcUI_Memory_t; FCUIDEF FcUI_Error_t FcUI_Memory(FcUI_Memory_t** pMemory, size_t mSize, size_t mSizePaddingNULL); FCUIDEF FcUI_Error_t FcUI_Memory_setData(FcUI_Memory_t* pMemory, size_t dataOffset, uint8_t* pData, size_t dataSize); FCUIDEF uint8_t* FcUI_Memory_getData(FcUI_Memory_t* pMemory, size_t dataOffset, size_t dataSize); FCUIDEF size_t FcUI_Memory_getSize(FcUI_Memory_t* pMemory); FCUIDEF FcUI_Error_t FcUI_Memory_free(FcUI_Memory_t** pMemory); FCUIDEF FcUI_Error_t FcUI_Memory(FcUI_Memory_t** pMemory, size_t mSize, size_t mSizePaddingNULL) { FcUI_Error_t mError; uint8_t* mData; size_t i; mError = FCUI_ERROR_NOERROR; FCUISAFECALL(mError, (pMemory), FCUI_ERROR_PARAMETERS); if (mSize != 0){ mData = (uint8_t*)realloc(*pMemory, mSize + sizeof(FcUI_Memory_t) + mSizePaddingNULL); if (mData) { *pMemory = (FcUI_Memory_t*)mData; (*pMemory)->mSize = mSize; (*pMemory)->mSizePadding = mSizePaddingNULL; for (i = mSize; i < mSize + mSizePaddingNULL; i++) (*pMemory)->mData[i] = 0; } FCUISAFECALL(mError, mData, FCUI_ERROR_OOM); } gError: return mError; } FCUIDEF FcUI_Error_t FcUI_Memory_setData(FcUI_Memory_t* pMemory, size_t dataOffset, uint8_t* pData, size_t dataSize) { size_t i, j; FcUI_Error_t mError = FCUI_ERROR_NOERROR; FCUISAFECALL(mError, pMemory, FCUI_ERROR_PARAMETERS); dataSize = min(dataOffset + dataSize, pMemory->mSize); for (i = dataOffset, j = 0; i < dataSize; i++, j++) { pMemory->mData[i] = pData[j]; } for (i = pMemory->mSize; i < pMemory->mSize + pMemory->mSizePadding; i++) { pMemory->mData[i] = 0; } gError: return mError; } FCUIDEF uint8_t* FcUI_Memory_getData(FcUI_Memory_t* pMemory, size_t dataOffset, size_t dataSize) { uint8_t* mPointer; mPointer = NULL; if (pMemory) mPointer = pMemory->mSize < dataOffset + dataSize ? NULL : pMemory->mData + dataOffset; return mPointer; } FCUIDEF FcUI_Error_t FcUI_Memory_free(FcUI_Memory_t** pMemory) { FcUI_Error_t mError; mError = FCUI_ERROR_NOERROR; FCUISAFECALL(mError, pMemory, FCUI_ERROR_PARAMETERS); free(*pMemory); *pMemory = NULL; gError: return mError; } FCUIDEF size_t FcUI_Memory_getSize(FcUI_Memory_t* pMemory){ return pMemory ? pMemory->mSize : 0; } #endif //_FCUI_MEMORY_H_