Memory allocation?

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
jcooper
Posts: 23
Joined: Tue Jul 08, 2008 7:29 pm
Contact:

Memory allocation?

Post by jcooper »

What is the protocol for mallocing when programming on the PICMicro chips? I've got a line like this:

char *data_array;
data_array = (char *)malloc(4);

When I try to compile it, I get an error saying, "Error - could not find definition of symbol 'malloc' in file './CAN.o'."

I have already included stdlib.h and all of the other standard includes.
No trees were harmed in the posting of this message. However, a large number of electrons were terribly inconvenienced.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Memory allocation?

Post by Benj »

Hello

If you have enough free memory in your device then you could always define the array as a static size eg

char data_array[4];

or

static char data_array[4];

Some compilers do support the malloc function so you will need to find the correct compiler or library that supports the malloc statement.

All the malloc statement is doing is trying to find some free bytes in the memory. If your memory is large or still has room then you will not need to do this function.

Post Reply