- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I'm having an issue with CyU3PMemAlloc. I found this thread, but there were no solutions. Basically I ask CyU3PMemAlloc for 16 bytes and it returns 4 bytes. Let me give a little context. So CommandOutQueue is type uint8_t**. I first allocate sizeof(uint8_t*) (4 bytes) for CommandOutQueue, and then allocate 16 bytes for CommandOutQueue[0]. This code is slightly simplified, but it boils down to:
CommandOutQueue = CyU3PMemAlloc(sizeof(uint8_t*));
MBIMCommandOutQueue[0] = CyU3PMemAlloc(16);
CyU3PDebugPrint(4,"\n\rsizeof(CommandOutQueue[0]) = %d",i,sizeof(CommandOutQueue[0]);
Which gives
sizeof(CommanOutQueue[0]) = 4
on the debug console.
The behavior is really odd, because it doesn't return null which is the error condition. What's also strange is that it doesn't throw a segfault when my code address outside of the 4 bytes. I only realized there was problem when I later needed to know the size of the CommandOutQueue[0] and it returned 4 which caused a cascade of other issues. By the way I'm confident there is at least 16 bytes left on the stack. If anyone has faced similiar issues, how did you get around them?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Nathan,
This is Madhu who is handling the Tech Support case you created regarding the same issue.
I was able to reprduce this and I am checking this with our software team. I will let you know y tomorrow via MyCases and will also reply in this forum thread.
Regards,
- Madhu Sudhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi please provide the update in this thread.
Thanks,
Arun
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Arun,
There is no issue with the CyU3PMemAlloc API. The issue reported in this thread is an user error. The sizeof operator returns only the size of the pointer address which is always 4 bytes. The sizeof operator cannot be used to find out the size of allocated memery.
If CyU3PMemAlloc does not return NULL, it means that the requested memory has been allocated.
Regards,
- Madhu Sudhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://www.cypress.com/?app=forum&id=167&rID=104377
Then please clear my query in this thread.
Thanks,
Arun.