Size: a a a

2021 February 14

s

std::slavik in supapro.cxx
можно смотреть размер свободного блока максимальный текущий конечно перед выделением
источник

FS

Flower Surgeon in supapro.cxx
/shrug
источник

F

FailsBot in supapro.cxx
¯\_(ツ)_/¯
источник

s

std::slavik in supapro.cxx
но никто не гарантирует что между моментом когда размер блока был проверен и моментом вызова new этот блок останется таким же
источник

AM

Aleksander Mironov in supapro.cxx
std::slavik
можно смотреть размер свободного блока максимальный текущий конечно перед выделением
А вот что так можно делать не знал.
Думал кучу свободную отслеживать в отдельном таске, вот это думаю тоже туда надо добавить.
источник

s

std::slavik in supapro.cxx
Aleksander Mironov
А вот что так можно делать не знал.
Думал кучу свободную отслеживать в отдельном таске, вот это думаю тоже туда надо добавить.
https://arduino-esp8266.readthedocs.io/en/latest/faq/a02-my-esp-crashes.html

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/heap_debug.html

там есть в SDK функции для этого всего - и поскольку проблемы с памятью возникают регулярно - использовать их скорей всего придется
источник

s

std::slavik in supapro.cxx
вместо исключения предлагают memory allocation failed hook
источник

s

std::slavik in supapro.cxx
Aleksander Mironov
ну я все поэтому на статической по максимуму делаю. В куче только всякая мелочь - по паре десятков байт размером. Ходит.
ага - особенно конкатенация строк очень быстро кучу в решето превращает:
Running out of heap is the most common cause for crashes. Because the build process for the ESP leaves out exceptions (they use memory), memory allocations that fail will do so silently. A typical example is when setting or concatenating a large String. If allocation has failed internally, then the internal string copy can corrupt data, and the ESP will crash.

In addition, doing many String concatenations in sequence, e.g.: using operator+() multiple times, will cause memory fragmentation. When that happens, allocations may silently fail even though there is enough total heap available. The reason for the failure is that an allocation requires finding a single free memory block that is large enough for the size being requested. A sequence of String concatenations causes many allocations/deallocations/reallocations, which makes “holes” in the memory map. After many such operations, it can happen that all available holes are too small to comply with the requested size, even though the sum of all holes is greater than the requested size.

So why do these silent failures exist? On the one hand, there are specific interfaces that must be adhered to. For example, the String object methods don’t allow for error handling at the user application level (i.e.: no old-school error returns). On the other hand, some libraries don’t have the allocation code accessible for modification. For example, std::vector is available for use. The standard implementations rely on exceptions for error handling, which is not available for the ESP, and in any case there is no access to the underlying code.
источник

s

std::slavik in supapro.cxx
но у esp проблема еще в том что там сетевой стек крутится и чего он там выделяет когда не угадаешь
источник

C

CodeDetector in supapro.cxx
std::slavik
ага - особенно конкатенация строк очень быстро кучу в решето превращает:
Running out of heap is the most common cause for crashes. Because the build process for the ESP leaves out exceptions (they use memory), memory allocations that fail will do so silently. A typical example is when setting or concatenating a large String. If allocation has failed internally, then the internal string copy can corrupt data, and the ESP will crash.

In addition, doing many String concatenations in sequence, e.g.: using operator+() multiple times, will cause memory fragmentation. When that happens, allocations may silently fail even though there is enough total heap available. The reason for the failure is that an allocation requires finding a single free memory block that is large enough for the size being requested. A sequence of String concatenations causes many allocations/deallocations/reallocations, which makes “holes” in the memory map. After many such operations, it can happen that all available holes are too small to comply with the requested size, even though the sum of all holes is greater than the requested size.

So why do these silent failures exist? On the one hand, there are specific interfaces that must be adhered to. For example, the String object methods don’t allow for error handling at the user application level (i.e.: no old-school error returns). On the other hand, some libraries don’t have the allocation code accessible for modification. For example, std::vector is available for use. The standard implementations rely on exceptions for error handling, which is not available for the ESP, and in any case there is no access to the underlying code.
Всё ещё неправильно :( Оберните код в теги: 3 символа ` до и после кода (в случае одиночной конструкции достаточно 1 ` с обеих сторон). Спасибо!
источник

ВШ

Виталий Шанин... in supapro.cxx
Народ привет, только изучаю Си, подскажите где торможу, почему avr не считает остатки?
источник

ВШ

Виталий Шанин... in supapro.cxx
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5

int main()
{
   int x[N], i, sum;
   float avr;
   srand (time(NULL));
   for (i=0; i<N; i++)
   {
       x[i] = rand()%10;
       printf("%d\n", x[i]);
   }
   for(i=0; i<N; i++)
   {
       sum+=x[i];
   }
   avr = sum/N;
   printf("sum = %d, avr = %f", sum, avr);
   return 0;
}
источник

C

CodeDetector in supapro.cxx
Виталий Шанин
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5

int main()
{
   int x[N], i, sum;
   float avr;
   srand (time(NULL));
   for (i=0; i<N; i++)
   {
       x[i] = rand()%10;
       printf("%d\n", x[i]);
   }
   for(i=0; i<N; i++)
   {
       sum+=x[i];
   }
   avr = sum/N;
   printf("sum = %d, avr = %f", sum, avr);
   return 0;
}
Оберните код в теги: 3 символа ` до и после кода (в случае одиночной конструкции достаточно 1 ` с обеих сторон). Спасибо!
источник

s

std::slavik in supapro.cxx
Виталий Шанин
Народ привет, только изучаю Си, подскажите где торможу, почему avr не считает остатки?
потому что он считает sum/N?
источник

s

std::slavik in supapro.cxx
выглядит как average
источник

VV

Vadim Voitenko in supapro.cxx
Виталий Шанин
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5

int main()
{
   int x[N], i, sum;
   float avr;
   srand (time(NULL));
   for (i=0; i<N; i++)
   {
       x[i] = rand()%10;
       printf("%d\n", x[i]);
   }
   for(i=0; i<N; i++)
   {
       sum+=x[i];
   }
   avr = sum/N;
   printf("sum = %d, avr = %f", sum, avr);
   return 0;
}
потому что sum интовый, а avr - флоат
источник

ВШ

Виталий Шанин... in supapro.cxx
т.е. не важно что sum всегда будет целочисленным, если я хочу делить его с остатком он должен быть float?
источник

D

Danya in supapro.cxx
@setpoint_f Я дописал пример :D
https://godbolt.org/z/n67Yj1
источник

D

Danya in supapro.cxx
Рекомендую начать с мейна и вывода в консоль
источник

D

Danya in supapro.cxx
Как ты и хотел — один шаблон
источник