- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Is it valid to use malloc()/calloc() functions with CyU3PByteAlloc()/CyU3PMemAlloc()?
I need to use some functions like strdup() that uses malloc() internally.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I had the same problem dealing with malloc() function. Though it is a part of standard library (stdlib.h) i got an error message saying "undefined reference to `_sbrk' line 0 C/C++ Problem".
And usage of CyU3PMemAlloc() and CyU3PMemFree() is not as dependable as I faced issues while allocating and freeing memory for larger iterations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@eAR, solution for your issue is very simple: just add file cyfxcppsyscall.cpp to likage. It contains "implementation" for all required syscalls. _sbrk() too.
But, I don't fully understand how to _sbrk() works and is it legal to mix malloc() and pool-based memory allocations?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes that's again a concern on whether malloc will use memory spaces from CY_U3P_MEM_HEAP_SIZE as specified in cyfxtx.c . But sorry that I couldn't get the first part... are u suggesting me to include cyfxcppsyscall.cpp in my project ? orif I should link it in properties option , can you brief ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can try printing the address assigned using both functions separately would be my suggestion ! And also I faced an issue like once the heap pool is empty, even though if I free the memory using CyU3PMemFree(), I am running out of space and CyU3PMemAlloc() allocates null to my variables.. Have you faced any similar issues ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> are u suggesting me to include cyfxcppsyscall.cpp in my project ? orif I should link it in properties option , can you brief ?
cyfxcppsyscall.cpp located at the $FX3_INSTALL_PATH/firmware/common. It contains implementation for the some system calls that required by stdlib. As I right understand, this calls needed only by C++ applications. My project is C++ based so I use it as is. If your project is a plain C based, you can simple rename it to .c and add to project.
In short: in some situations you MUST provide implementation of the some calls required by used libraries.'
Look into: https://balau82.wordpress.com/2010/12/16/using-newlib-in-arm-bare-metal-programs/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Answer to my question:
with default ld-script it is valid to use malloc-family function. Malloc allocator uses it own memory area differ to default ThreadX mem-pool.