Redlib documentation missing?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Redlib documentation missing?

2,126 Views
danielholala
Senior Contributor II

Hi there,

I wonder if anybody has any documentation on Redlib, especially about reentrancy and dynamic memory allocation?

By default, MCUExpresso uses Redlib for new C projects. According to the IDE User Guide, NXP recommend the use of Redlib. So one would expect that there's documentation about a component at the core of an embedded project. However, I haven't found anything yet (except for some scarce information in the IDE User Guide).

I'm interested how Redlib handles notoriously non-reentrant functions like strtok(). Additionally I'd like to know how Redlib uses dynamic memory allocation, e.g., whether snprintf() does any calls to malloc()/free()

Obviously, there's no source code for Redlib available so I can not check for myself. According to the header files, there are no explicitly reentrant counterparts like strtok_r() available.

Thanks.

Daniel

2 Replies

1,589 Views
lpcxpresso_supp
NXP Employee
NXP Employee

Sorry, as we have already told you in a previous post, all the of user information that we have for Redlib is included in the IDE's User Guide.

Redlib was always designed as a simple, Embedded C library. And at present we have no plans to make it thread safe - we have seen little or no demand for this (in the 10 years or so that we have been supplying Redlib). 

Our recommendation if you want thread safe is to use Newlib (which you can switch your project to use very easily), wrap the Redlib functions yourself, or else provide equivalent functions yourself as source within your project (e.g. from other open source projects).

With regards to snprintf, basically the way that the whole Redlib stdio family of functions is written means that you are always likely to end up with an element of heap usage. To confirm what is being pulled in, always check the .map file generated by the linker (and potentially add the --cref option to the Linker's misc options).

Regards,

MCUXpresso IDE Support

0 Kudos

1,589 Views
danielholala
Senior Contributor II

Thanks for replying and clearly stating that Redlib is not threadsafe.

Regarding switching to newlib, I agree this will aid in solving reentrancy issues but might pull in a different set of issues as pointed out in this thread. Thus I did not switch to newlib but use other measures to handle multithreading and dynamic memory issues as set out below.

Regarding snprintf(), I followed your advice and replaced it by a minimal alternative implementation. printf(), strtok(), etc. will not be used at all. 

Regarding the use of heap, I don't mind the carefully considered use of malloc() as long as free() is not called :-). To safeguard against the (hidden) use of  dynamic memory allocation, I provided my own implementation of char * _sbrk(int incr) { __asm("BKPT #0\n"); return 0; } to catch calls to malloc().

In other words, I'd like to be in the driving seat when it comes to usage of heap. Therefore I'd appreciate if you could briefly set forth how to decipher the .map file with regard to heap usage. I'm at a loss how to do this and doubt that one can extract the required information from a static view of the memory layout that a map files provides.

Thanks a lot!

Daniel