This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Building a realloc function?

Hey guys,

since realloc isn't ANSI C and for that not support by KEIL I tried to create my own realloc function.

But - as usual - I have some pointer trouble :-/ .

Here is my try for this memory reallocation function. But it doesn't compile because of the statement in the for loop:

void* Memrealloc(void* pvMem, uint32_t ulNewSize)
{
int i;
char *ptr; //Pointer for the new memory area

ptr = (char*)malloc(ulNewSize);  //Allocating the amount of requested memory

for (i=0; i<=ulNewSize;i++)
{
ptr[i]=(char*)pvMem[i];  //Copy the old content of the memory
}

free (pvMem);       //Deallocating the old memory

return (void*)ptr;   //Returning pointer to the new memory
}

Thats the error I get:
Source\OS_Custom.c(79): error: #852: expression must be a pointer to a complete object type

What is happening here? What do I have to do to fix it?

Parents
  • I would have a problem, if malloc really will use 32-bit access - wouldn't I?
    How can I find out, which bitwidth malloc uses when accessing the memory?

    Note that I didn't say malloc(). I said memset(), memcmp() and others. This issue doesn't apply to malloc().

    I guess I have to tell my linker that it should use malloc only to allocate memory from the external ram.

    Well, I don't know. Normally, you would do this if you had insufficient on-chip RAM and plenty of external RAM.

    I think you should develop some understanding of the way your program is supposed to work. Simple instructions like 'use external RAM for heap' can easily be irrelevant to your situation. There can be subtle issues involved.

Reply
  • I would have a problem, if malloc really will use 32-bit access - wouldn't I?
    How can I find out, which bitwidth malloc uses when accessing the memory?

    Note that I didn't say malloc(). I said memset(), memcmp() and others. This issue doesn't apply to malloc().

    I guess I have to tell my linker that it should use malloc only to allocate memory from the external ram.

    Well, I don't know. Normally, you would do this if you had insufficient on-chip RAM and plenty of external RAM.

    I think you should develop some understanding of the way your program is supposed to work. Simple instructions like 'use external RAM for heap' can easily be irrelevant to your situation. There can be subtle issues involved.

Children
  • I said memset(), memcmp() and others.

    You are right. I guess I like assuming to much random stuff... :-)

    I think you should develop some understanding of the way your program is supposed to work.

    You are right, again. I will do that. I thought, that it would be a smart approach to first get all suggested requirements done, but I should really do some basic use of those functions first to see, what I actually need.

    I'll be back :)