I'm using some third-party code which uses malloc() and free() a lot, and would very much prefer not to modify the source.
From here, the default malloc() and free() are NOT thread-safe (I've not managed to find how they integrate with Chibi's heap management yet, although they appear to work!)
I've tried overriding both the re-entrant versions of the heap management (_malloc_r() etc) and the standard ones, but get 'duplicate definition' errors at link-time - this appears to be a 'well known' problem of newlib.
Has anyone else managed to achieve thread-safe heap management?
Heap Management
Moderators: RoccoMarco, lbednarz, utzig, tfAteba, barthess
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Heap Management
Is it possible to rework the code to use __malloc() and __free() instead? you could provide wrappers around the kernel heap allocator which is thread safe.
Giovanni
Giovanni
Re: Heap Management
Giovanni wrote:Is it possible to rework the code to use __malloc() and __free() instead?
That's exactly what I'm trying to avoid! As well as a large number of malloc() and free() calls, the code also uses strdup() and similar functions a lot; uncertain whether they'd also need rework.
I haven't found any definitive reference on __malloc() and __free() yet; from the few references I've found so far, they appear to usually resolve to malloc() and free(). Can you point me to any definition?
Giovanni wrote:you could provide wrappers around the kernel heap allocator which is thread safe.
I've done the wrappers; its linking them in that's causing issues. I'll probably pursue this route a bit further first.
Incidentally, a small point concerning free()/chHeapFree(). According to this, free(0) is legitimate coding, and does nothing. chHeapFree(0) gives an error if debugging is enabled. A difference which could catch people out.
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Heap Management
Hi,
__malloc and __free are names I invented, I meant to redirect all calls to other functions that you would provide.
Giovanni
__malloc and __free are names I invented, I meant to redirect all calls to other functions that you would provide.
Giovanni
Re: Heap Management
Giovanni wrote:__malloc and __free are names I invented, I meant to redirect all calls to other functions that you would provide.
That explains it! From my searches, you're not the first to use those names.
Who is online
Users browsing this forum: No registered users and 19 guests