Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use malloc( ) and free( ) in PICC?

Status
Not open for further replies.

kerden

Junior Member level 3
Joined
Dec 11, 2004
Messages
25
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
284
pic malloc

I have writed a simple program like this:
/* ******************************* */
#include<stdlib.h>

void main(void)
{
unsigned char *ptr;

ptr = (unsigned char *) malloc(sizeof(unsigned char));
free(ptr);
}
/* ***************************** */
This just used to test how to use malloc() and free() in PICC.But after compiled,some error message appear:
Error[000] : undefined symbols:
Error[000] : _free (D:\MPLAB IDE\PICproject\Test\test.obj)
Error[000] : _malloc (D:\MPLAB IDE\PICproject\Test\test.obj)

I have doubt in why these error message appear.How to do dynamic memory's program such use malloc() and free() in PICC?
Best regards,
 

malloc pic

Hi,

To use malloc() and free() you need to include stdlib.h

Regards.
 

pic18f malloc

crevars said:
Hi,

To use malloc() and free() you need to include stdlib.h

Regards.

yes !
i have included stdlib.h
 

pic18 malloc

Ho sorry, I don't know why, my browser didn't show me the <stdlib.h>....
I've tested your code on my mplab with picc18 and it's work. May be you have a problem with your library installation....I don't think picc and picc18 are different when using free() and malloc().
 

mcc18 malloc

I think it has no heap space in pic mircocontroller.
but malloc() and free() are used to control heap in personal computer.

I think the reason is from PIC compiler
 

hi-tech malloc

crevars said:
Ho sorry, I don't know why, my browser didn't show me the <stdlib.h>....
I've tested your code on my mplab with picc18 and it's work. May be you have a problem with your library installation....I don't think picc and picc18 are different when using free() and malloc().


thank you very much.
i ve also tested my code with picc and picc18,but i doesn't work.are you picc18 is a demo? where have you downloaded?
 

malloc et pic

My picc18 it's not a demo....but I think your code could work with a demo version. Try to put stdlib.h in the directory of your simple program and put #include "stdlib.h" instead.
 

malloc() mcc18

crevars said:
My picc18 it's not a demo....but I think your code could work with a demo version. Try to put stdlib.h in the directory of your simple program and put #include "stdlib.h" instead.


i have copy the stdlib.h under the project file.but it doesn't work;
some error as follow


The target "D:\picc\PIC18\fgh.obj" is already up to date.
Executing: "C:\HTSOFT\PIC18\BIN\PICC18.EXE" -E"2.lde" "D:\picc\PIC18\fgh.obj" -M"2.map" -O"2.cof" -O"2.hex" -Q -MPLAB -18F248
Error[000] : undefined symbols:
Error[000] : _free (D:\picc\PIC18\fgh.obj)
Error[000] : _malloc (D:\picc\PIC18\fgh.obj)
Error[000] D:\picc\PIC18\fgh.obj 17 : Fixup overflow in expression (loc 0x20 (0x1C+4), size 1, value 0x100)
Error[000] D:\picc\PIC18\fgh.obj 17 : Fixup overflow in expression (loc 0x22 (0x1C+6), size 1, value 0x101)
Error[000] fgh.rlf 24 : Fixup overflow in expression (loc 0x1 (0x1+0), size 1, value 0x100)
Error[000] fgh.rlf 28 : Fixup overflow in expression (loc 0x1 (0x1+0), size 1, value 0x101)
BUILD FAILED: Fri Mar 24 18:59:03 2006
 

malloc mcc18

If you look at the application notes on Microchip website you will find some c code for dynamic allocation of Ram using homebrewed malloc and free. You have to modify the linker file to get some heap memory from which to allocate and free ram.
I am using my own version of it for a linked list and it works just fine.
I am using Microchips Mcc18 compiler for the 18 series. I much prefer it to Hi-Tech.
Hi-Tech is ok for the low end 16 series
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top