Closed mrquincle closed 3 years ago
This particular call allocates 520 bytes and frees 520 bytes in quick succession.
Another reason not do memory allocation in print statements, is that it makes it harder to put print statements in memory allocation routines.
cs_log_printf is meant as a convenience in case you don't want to use binary logging. If you care about memory and speed, use binary logging instead. An option would be to simply ignore any cs_log_printf that would need more than 128B, or maybe we could use cs_clog instead, which streams directly to uart instead of to a buffer first.
On Thu, 4 Feb 2021 at 21:50, Anne van Rossum notifications@github.com wrote:
Another reason not do memory allocation in print statements, is that it makes it harder to put print statements in memory allocation routines.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/crownstone/bluenet/issues/98#issuecomment-773595376, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAPLGQJMQSX3SWB46VOQ6OLS5MB7VANCNFSM4XDIUNKA .
Check. The buffer of size UART_TX_BUFFER_SIZE
has a different function that I anticipated. It is used as an intermediate buffer to write into from, for example, the ADC. This can be done asynchronously. That is, in the meantime other things can be written to the console. Hence, this buffer is hard to re-use for this purpose.
Easy to implement would then be the removal of malloc
for non binary logging. Hence, just use snprintf
and write up to n
. Due to the fact that __func__
takes many bytes, it might be worthwhile to only print the data without prefix.
Fixed with 45b984ce3b2f005cbd7fa3a674722cc1b902e00d
A call to
cs_log_printf
is not restricted in size.It should make use of the outgoing uart buffer. The C and C++ code should not use different buffers. There should not be dynamic memory allocation for print statements.