mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 11:16:34 +00:00
refactor ESP_getMaxAllocHeap()
This commit is contained in:
parent
9f1da8489e
commit
31660da843
@ -48,7 +48,26 @@ uint32_t ESP_getFreeHeap(void) {
|
||||
}
|
||||
|
||||
uint32_t ESP_getMaxAllocHeap(void) {
|
||||
return ESP.getMaxFreeBlockSize();
|
||||
/*
|
||||
From libraries.rst
|
||||
ESP.getMaxFreeBlockSize() returns the largest contiguous free RAM block in
|
||||
the heap, useful for checking heap fragmentation. **NOTE:** Maximum
|
||||
``malloc()``able block will be smaller due to memory manager overheads.
|
||||
|
||||
From HeapMetric.ino
|
||||
ESP.getMaxFreeBlockSize() does not indicate the amount of memory that is
|
||||
available for use in a single malloc call. It indicates the size of a
|
||||
contiguous block of (raw) memory before the umm_malloc overhead is removed.
|
||||
|
||||
It should also be pointed out that, if you allow for the needed overhead in
|
||||
your malloc call, it could still fail in the general case. An IRQ handler
|
||||
could have allocated memory between the time you call
|
||||
ESP.getMaxFreeBlockSize() and your malloc call, reducing the available
|
||||
memory.
|
||||
*/
|
||||
uint32_t free_block_size = ESP.getMaxFreeBlockSize();
|
||||
if (free_block_size > 100) { free_block_size -= 100; }
|
||||
return free_block_size;
|
||||
}
|
||||
|
||||
void ESP_Restart(void) {
|
||||
@ -273,7 +292,10 @@ uint32_t ESP_getFreeHeap(void) {
|
||||
}
|
||||
|
||||
uint32_t ESP_getMaxAllocHeap(void) {
|
||||
return ESP.getMaxAllocHeap();
|
||||
// largest block of heap that can be allocated at once
|
||||
uint32_t free_block_size = ESP.getMaxAllocHeap();
|
||||
if (free_block_size > 100) { free_block_size -= 100; }
|
||||
return free_block_size;
|
||||
}
|
||||
|
||||
void ESP_Restart(void) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user