diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f59345..7be6735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Develop +## v2.2.0 + - Rework library CMake with removed INTERFACE type - Add `LWMEM_CFG_FULL` to allow control build configuration of the library - Implement support for simple (no realloc, no free, grow-only malloc) allocation mechanism diff --git a/README.md b/README.md index 0e1d0b6..4e73f86 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ * Supports embedded applications with fragmented memories * Supports automotive applications * Supports advanced free/realloc algorithms to optimize memory usage +* **Since v2.2.0** Supports light implementation with allocation only * Operating system ready, thread-safe API * C++ wrapper functions * User friendly MIT license diff --git a/docs/index.rst b/docs/index.rst index 152195e..63c3aba 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -25,6 +25,7 @@ Features * Supports embedded applications with fragmented memories * Supports automotive applications * Supports advanced free/realloc algorithms to optimize memory usage +* **Since v2.2.0** Supports light implementation with allocation only * Operating system ready, thread-safe API * C++ wrapper functions * User friendly MIT license diff --git a/docs/user-manual/index.rst b/docs/user-manual/index.rst index 6ead08e..7469f4b 100644 --- a/docs/user-manual/index.rst +++ b/docs/user-manual/index.rst @@ -9,4 +9,5 @@ User manual how-it-works instances realloc-algorithm + light-version thread-safety \ No newline at end of file diff --git a/docs/user-manual/light-version.rst b/docs/user-manual/light-version.rst new file mode 100644 index 0000000..3f8eada --- /dev/null +++ b/docs/user-manual/light-version.rst @@ -0,0 +1,19 @@ +.. _light_version: + +LwMEM light implementation +========================== + +When system is super memory constrained or when system only requires memory allocation at initialization stage, +it is possible to put the library into *light* mode by controlling the :c:macro:`LWMEM_CFG_FULL` user configuration option + +When *full* mode is disabled, user must be aware of some contraints: + +* It is only possible to allocate memory (no free, no realloc) +* It is only possible to use one (``1``) memory region. When assigning the memory with more than one region, function will return an error. + +.. tip:: + Light mode is useful for opaque types that are returned to user and must be allocated on the heap. + These are typically allocated at initialization stage and never freed during program execution. + +.. toctree:: + :maxdepth: 2 diff --git a/library.json b/library.json index a7197fa..aa4ac05 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "LwMEM", - "version": "2.1.0", + "version": "2.2.0", "description": "Lightweight dynamic memory manager optimized for embedded systems", "keywords": "lwmem, memory, dynamic, heap, malloc, calloc, realloc, free, lightweight, manager, embedded, stm32, win32", "repository": { diff --git a/lwmem/src/include/lwmem/lwmem.h b/lwmem/src/include/lwmem/lwmem.h index 93b4057..7ff3ea1 100644 --- a/lwmem/src/include/lwmem/lwmem.h +++ b/lwmem/src/include/lwmem/lwmem.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #ifndef LWMEM_HDR_H #define LWMEM_HDR_H @@ -125,6 +125,7 @@ size_t lwmem_get_size_ex(lwmem_t* lwobj, void* ptr); #endif /* LWMEM_CFG_FULL || __DOXYGEN__ */ #if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ void lwmem_get_stats_ex(lwmem_t* lwobj, lwmem_stats_t* stats); +void lwmem_get_size(lwmem_stats_t* stats); #endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ size_t lwmem_assignmem(const lwmem_region_t* regions); @@ -137,20 +138,8 @@ int lwmem_realloc_s(void** ptr2ptr, size_t size); void lwmem_free(void* ptr); void lwmem_free_s(void** ptr2ptr); size_t lwmem_get_size(void* ptr); - #endif /* LWMEM_CFG_FULL || __DOXYGEN__ */ -#if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ - -/** - * \note This is a wrapper for \ref lwmem_get_stats_ex function. - * It operates in default LwMEM instance - * \param[in] ptr: Pointer to lwmem_stats_t to store result - */ -#define lwmem_get_stats(stats) lwmem_get_stats_ex(NULL, (stats)) - -#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ - #if defined(LWMEM_DEV) && !__DOXYGEN__ unsigned char lwmem_debug_create_regions(lwmem_region_t** regs_out, size_t count, size_t size); void lwmem_debug_save_state(void); diff --git a/lwmem/src/include/lwmem/lwmem.hpp b/lwmem/src/include/lwmem/lwmem.hpp index ae218b1..cad3dab 100644 --- a/lwmem/src/include/lwmem/lwmem.hpp +++ b/lwmem/src/include/lwmem/lwmem.hpp @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #ifndef LWMEM_HDR_HPP #define LWMEM_HDR_HPP diff --git a/lwmem/src/include/lwmem/lwmem_opt.h b/lwmem/src/include/lwmem/lwmem_opt.h index 4465f3f..e0b7df1 100644 --- a/lwmem/src/include/lwmem/lwmem_opt.h +++ b/lwmem/src/include/lwmem/lwmem_opt.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #ifndef LWMEM_OPT_HDR_H #define LWMEM_OPT_HDR_H @@ -89,7 +89,7 @@ extern "C" { * \brief Enables `1` or disables `0` full memory management support. * * When enabled (default config), library supports allocation, reallocation and freeing of the memory. - * - Memory allocation and [c]allocation + * - Memory [c]allocation * - Memory reallocation * - Memory allocation in user defined memory regions * - Memory freeing diff --git a/lwmem/src/include/lwmem/lwmem_opts_template.h b/lwmem/src/include/lwmem/lwmem_opts_template.h index e7b92c8..68dbfa6 100644 --- a/lwmem/src/include/lwmem/lwmem_opts_template.h +++ b/lwmem/src/include/lwmem/lwmem_opts_template.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #ifndef LWMEM_OPTS_HDR_H #define LWMEM_OPTS_HDR_H diff --git a/lwmem/src/include/system/lwmem_sys.h b/lwmem/src/include/system/lwmem_sys.h index c6a92ab..841b7d4 100644 --- a/lwmem/src/include/system/lwmem_sys.h +++ b/lwmem/src/include/system/lwmem_sys.h @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #ifndef LWMEM_SYS_HDR_H #define LWMEM_SYS_HDR_H diff --git a/lwmem/src/lwmem/lwmem.c b/lwmem/src/lwmem/lwmem.c index cf92bb2..9300227 100644 --- a/lwmem/src/lwmem/lwmem.c +++ b/lwmem/src/lwmem/lwmem.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #include "lwmem/lwmem.h" #include @@ -1146,7 +1146,7 @@ lwmem_get_size_ex(lwmem_t* lwobj, void* ptr) { * \brief Get statistics of a LwMEM instance * \param[in] lwobj: LwMEM instance. Set to `NULL` to use default instance. * Instance must be the same as used during allocation procedure - * \param[in] stats: Pointer to \ref lwmem_stats_t to store result + * \param[in,out] stats: Pointer to \ref lwmem_stats_t to store result */ void lwmem_get_stats_ex(lwmem_t* lwobj, lwmem_stats_t* stats) { @@ -1159,6 +1159,15 @@ lwmem_get_stats_ex(lwmem_t* lwobj, lwmem_stats_t* stats) { } } +/** + * \brief Get statistics of a default LwMEM instance + * \param[in,out] stats: Pointer to \ref lwmem_stats_t to store result + */ +size_t +lwmem_get_size(lwmem_stats_t* stats) { + lwmem_get_stats_ex(NULL, stats); +} + #endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */ /** diff --git a/lwmem/src/lwmem/lwmem.cpp b/lwmem/src/lwmem/lwmem.cpp index 4229285..ea5fc14 100644 --- a/lwmem/src/lwmem/lwmem.cpp +++ b/lwmem/src/lwmem/lwmem.cpp @@ -29,5 +29,5 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ diff --git a/lwmem/src/system/lwmem_sys_cmsis_os.c b/lwmem/src/system/lwmem_sys_cmsis_os.c index 16ecb60..9db2f44 100644 --- a/lwmem/src/system/lwmem_sys_cmsis_os.c +++ b/lwmem/src/system/lwmem_sys_cmsis_os.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #include "system/lwmem_sys.h" diff --git a/lwmem/src/system/lwmem_sys_threadx.c b/lwmem/src/system/lwmem_sys_threadx.c index af4b7ee..500c0e2 100644 --- a/lwmem/src/system/lwmem_sys_threadx.c +++ b/lwmem/src/system/lwmem_sys_threadx.c @@ -29,7 +29,7 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #include "system/lwmem_sys.h" diff --git a/lwmem/src/system/lwmem_sys_win32.c b/lwmem/src/system/lwmem_sys_win32.c index 2b29ac0..3a50386 100644 --- a/lwmem/src/system/lwmem_sys_win32.c +++ b/lwmem/src/system/lwmem_sys_win32.c @@ -29,13 +29,13 @@ * This file is part of LwMEM - Lightweight dynamic memory manager library. * * Author: Tilen MAJERLE - * Version: v2.1.0 + * Version: v2.2.0 */ #include "system/lwmem_sys.h" #if LWMEM_CFG_OS && !__DOXYGEN__ -#include "Windows.h" +#include "windows.h" uint8_t lwmem_sys_mutex_create(LWMEM_CFG_OS_MUTEX_HANDLE* m) { @@ -50,12 +50,7 @@ lwmem_sys_mutex_isvalid(LWMEM_CFG_OS_MUTEX_HANDLE* m) { uint8_t lwmem_sys_mutex_wait(LWMEM_CFG_OS_MUTEX_HANDLE* m) { - DWORD ret; - ret = WaitForSingleObject(*m, INFINITE); - if (ret != WAIT_OBJECT_0) { - return 0; - } - return 1; + return WaitForSingleObject(*m, INFINITE) == WAIT_OBJECT_0; } uint8_t