Is microblaze able to change heap_size?

Hi, I have written in this chat a pair of threads about Sdram and heap_size. I want to say that I think that heap_size cannot be changed with Microblaze. I need to do "xil_malloc(16*4096), but in SDRAM (32MB) I only can do "xil_malloc(15*4096)". Then I have increased "heap_size" in Linker Script since 0x400 to 0x1400000. I have put 24Mb for "heap_size" but it seems heap_size keeps as same as 0x400.

First of all I don't understand how can I do "xil_malloc(15*4096)" when I have a heap_size of 0x400 (1024 bytes).

Second. I don't know how can I increase my Memory Resources to malloc more memory.

Thanks and I hope you could help me.

Reply to
Pablo
Loading thread data ...

Forget about xil_malloc() and just use malloc().

-Ben-

Reply to
Ben Jones

But malloc doesn't work in Microblaze. Could you help me?. How can I do it?

Reply to
Pablo

Since when? I have never had any problems with it.

From the "LibXil Standard C Libraries" documentation: The MicroBlaze and PPC405 C libraries support all the standard memory management functions such as malloc(), calloc(), free()

There is nothing magical about malloc(). It's just an interface to a dynamically-allocatable wodge of memory. It doesn't have any dependencies on special processor features; in some environments it can make a system call to request more memory from the underlying OS, but with an embedded system it's more common just to have a fixed heap size.

-Ben-

Reply to
Ben Jones

Well I have increased heap_size and it seems ok, but when I add more code to my project it fails again and I know I have quite a lot memory since I have downloaded the app to the sdram with 32MB. I think malloc works abnormally. In some cases I have seen it work fine and in anothers it doesn`t work.

I suppose it has a reason but I don`t know what.

Thanks again for your help.

Reply to
Pablo

What evidence do you have that malloc() is not working, vs. something is your code is not working? Do you know that your code works when compiled for another system? The standard C library functions in the Xilinx toolchain are not proprietary. They are basically the same routines you'd get when using any other GNU-based cross-compiler.

So I would first of all try to isolate the failure in your code and see why it is failing. The most likely cause in an embedded system is running out of stack space, rather than heap space. This is particularly true when porting some software from a PC environment to an embedded system, because most PC programmers are extremely lazy about memory management and will happily allocated megabytes of temporary data on the stack without batting an eyelid...

Heap exhaustion is easy to catch because malloc() returns an error code. Stack overflows/corruption are much nastier and can have all sorts of hard-to-track-down side effects.

Cheers,

-Ben-

Reply to
Ben Jones

Well, you are ok. I am porting some software from a PC environment to an embedded system. But I don`t understand this:

- First I crate a simple main.c with a malloc(128*1024) . That is, I reserve memory for 128k. I edit linker script and program runs OK.

- Second I increase my code, adding some lines and four files. But I do ,at the first, the same memory reserve: malloc(128*1024), and I edit the linker script with the same size as the example above. But in this case malloc returns NULL.

I suppose I have to learn quite a lot, but I cannot understand how Malloc works with first example and not for the second one.

But, I must be thankful for your constructive commentary.

Regards, Pablo

Reply to
Pablo

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.