AP_Logger: try harder to use close to user buffer size

this stops us drastically reducing buffer size when low on memory
This commit is contained in:
Andrew Tridgell 2019-09-23 11:48:16 +10:00
parent 2d00298070
commit 3bf3ebb703
1 changed files with 6 additions and 2 deletions

View File

@ -83,10 +83,14 @@ void AP_Logger_File::Init()
}
bufsize *= 1024;
const uint32_t desired_bufsize = bufsize;
// If we can't allocate the full size, try to reduce it until we can allocate it
while (!_writebuf.set_size(bufsize) && bufsize >= _writebuf_chunk) {
hal.console->printf("AP_Logger_File: Couldn't set buffer size to=%u\n", (unsigned)bufsize);
bufsize >>= 1;
bufsize *= 0.9;
}
if (bufsize >= _writebuf_chunk && bufsize != desired_bufsize) {
hal.console->printf("AP_Logger: reduced buffer %u/%u\n", (unsigned)bufsize, (unsigned)desired_bufsize);
}
if (!_writebuf.get_size()) {