cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Visitor
Visitor
7,443 Views
Registered: ‎07-16-2014

why malloc corrupts memory but xil_malloc works?

Jump to solution

Hi,

 

I'm working with EDK 14.2 on an atlys board. In SDK I use to get a picture as a matrix from Uart and do some work on it.

 

The problem is that when I use malloc() function to allocate memory, it corrupts everything and the figure is corrupted. but when i replace that code with xil_malloc() it works fine and good job!

 

1.what is the problem with malloc?

2. The xillinx documentations say that xil_malloc is deprecated and we must use malloc. it says the problem with xil_malloc() is that it doesnt use dynamic memory and it uses a fixed 64k memory! so how should I use malloc 

 

 

NOTE: don't tell me to increase the heap size in "Generate linker script", because I putted heap&stack section in DDR2 and heaps size is about 9MB now. so this is not the problem I think!

 

any help would be appretiated.

size = 10;
image = (u8**)malloc(size * sizeof(u8));
for (i=0;i<size;i++)
	image[i] = (u8*)malloc(size * sizeof(u8));




//get image from Uart
	for(row=0;row<size;row++)
		for(col=0;col<size;col++)
			image[row][col] = get_byte();


//send image to uart
	for(row=0;row<size;row++)
		for(col=0;col<size;col++)
			put_byte(image[row][col]);
Do not go gentle into that goodnight. Rage, Rage, against the dying of the light!
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Visitor
Visitor
13,508 Views
Registered: ‎07-16-2014

The problem was nothing but a * :

 

image = (u8**)malloc(size * sizeof(u8*));

changing u8 to u8* corrected. sorry for bothering!

Do not go gentle into that goodnight. Rage, Rage, against the dying of the light!

View solution in original post

0 Kudos
1 Reply
Highlighted
Visitor
Visitor
13,509 Views
Registered: ‎07-16-2014

The problem was nothing but a * :

 

image = (u8**)malloc(size * sizeof(u8*));

changing u8 to u8* corrected. sorry for bothering!

Do not go gentle into that goodnight. Rage, Rage, against the dying of the light!

View solution in original post

0 Kudos