DSPRelated.com
Forums

malloc

Started by Simone Winkler January 2, 2005
Hello,

I'm developping code for a C6713 DSP (actually it's the D.SignT-module with 
the C6713 on it).
I'm trying to use malloc() but it doesn't seem to work. In the beginning I 
always received a null pointer. After a long while of searching my mistake I 
detected the section in the DSP/BIOS configuration for malloc(). I pointed 
it to SBSRAM and to SDRAM but both solutions didnt work - in the end I got 
an error that told me that I tried to read data from memory location ... in 
L2. The command I use simply says "malloc(1)" - just to try...
At the moment I'm using the emulator because I can't run the board at home, 
but I think this cannot be the problem.

Can you help me?

Thank you,
Simone 


> I'm developping code for a C6713 DSP (actually it's the D.SignT-module > with the C6713 on it). > I'm trying to use malloc() but it doesn't seem to work. In the beginning I > always received a null pointer. After a long while of searching my mistake > I detected the section in the DSP/BIOS configuration for malloc(). I > pointed it to SBSRAM and to SDRAM but both solutions didnt work
Have you created a heap in the MEM section (e.g. SDRAM) where you want the allocation to take place? You need to enter a valid heap size, set the memory space to data or code/data, and I think also put the same value in the linker heap size setting (in Build Options, assuming you're using CCS) Tom
On Sun, 2 Jan 2005 22:14:17 +0100, "Simone Winkler"
<simone.winkler@gmx.at> wrote:

>I'm developping code for a C6713 DSP (actually it's the D.SignT-module with >the C6713 on it). >I'm trying to use malloc() but it doesn't seem to work. In the beginning I >always received a null pointer. After a long while of searching my mistake I >detected the section in the DSP/BIOS configuration for malloc().
?? as far as I know you are not supposed to use malloc while using DSP/BIOS - with DSP/BIOS there are some functions MEM_alloc or something like that to manage memory - you can't use the "ordinary" malloc!! but then - what do I know?
> ?? as far as I know you are not supposed to use malloc while using > DSP/BIOS - with DSP/BIOS there are some functions MEM_alloc or > something like that to manage memory - you can't use the "ordinary" > malloc!!
As far as I know, malloc uses MEM_alloc with seg_id of 1 (or similar...). I'm not quite sure! Thank you, Simone
On Sun, 02 Jan 2005 23:41:26 +0100, karol kluska <adres15@op.pl> wrote:
> On Sun, 2 Jan 2005 22:14:17 +0100, "Simone Winkler" ><simone.winkler@gmx.at> wrote: > >>I'm developping code for a C6713 DSP (actually it's the D.SignT-module with >>the C6713 on it). >>I'm trying to use malloc() but it doesn't seem to work. In the beginning I >>always received a null pointer. After a long while of searching my mistake I >>detected the section in the DSP/BIOS configuration for malloc(). > > ?? as far as I know you are not supposed to use malloc while using > DSP/BIOS - with DSP/BIOS there are some functions MEM_alloc or > something like that to manage memory - you can't use the "ordinary" > malloc!! > > but then - what do I know?
You can use malloc if your memory configuration supports it. The C Compiler Reference for the 'c6x family discusses this at some length. When I was working with TI chips, I tended to avoid malloc, because all of my data was really static at the end of the day, though occasionally it was required for other reasons. See if maybe some "non embedded system" thinking is creeping into your brain. It's quite a different mindset from general applications programming.
Simone Winkler wrote:

> Hello, > > I'm developping code for a C6713 DSP (actually it's the D.SignT-module with > the C6713 on it). > I'm trying to use malloc() but it doesn't seem to work. In the beginning I > always received a null pointer. After a long while of searching my mistake I > detected the section in the DSP/BIOS configuration for malloc(). I pointed > it to SBSRAM and to SDRAM but both solutions didnt work - in the end I got > an error that told me that I tried to read data from memory location ... in > L2. The command I use simply says "malloc(1)" - just to try... > At the moment I'm using the emulator because I can't run the board at home, > but I think this cannot be the problem. > > Can you help me? > > Thank you, > Simone
Maybe you can help me to understand how malloc() might be used in an embedded system. I assume that there is no virtual memory (swapping to disk) available, and that the routines to be run use fixed-size arrays and buffers. It is never necessary to allocate memory unless it will also be de-allocated later. Although I have sometimes needed to use the same memory space sequentially for different routines, I've never encountered a situation that prevented me from allocating all the space I needed at compile time. What would you use malloc() for? Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Wed, 05 Jan 2005 11:41:49 -0500, Jerry Avins <jya@ieee.org> wrote:

> I've never >encountered a situation that prevented me from allocating all the space >I needed at compile time. What would you use malloc() for?
If man wasn't meant to eat animals, they wouldn't be made out of food. if it wasn't needed - malloc would not be included in embedded libc ports - right? ;-)
karol kluska wrote:

> On Wed, 05 Jan 2005 11:41:49 -0500, Jerry Avins <jya@ieee.org> wrote: > > >>I've never >>encountered a situation that prevented me from allocating all the space >>I needed at compile time. What would you use malloc() for? > > > If man wasn't meant to eat animals, they wouldn't be made out of food. > > if it wasn't needed - malloc would not be included in embedded libc > ports - right? ;-)
Did I seem to imply that malloc() shouldn't be used? If so, I wasn't clear. I asked how it might be used, i.e., what makes it useful. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Wed, 05 Jan 2005 12:12:33 -0500, Jerry Avins <jya@ieee.org> wrote:

>>>I've never >>>encountered a situation that prevented me from allocating all the space >>>I needed at compile time. What would you use malloc() for? >> >> >> If man wasn't meant to eat animals, they wouldn't be made out of food. >> >> if it wasn't needed - malloc would not be included in embedded libc >> ports - right? ;-) > >Did I seem to imply that malloc() shouldn't be used? If so, I wasn't >clear. I asked how it might be used, i.e., what makes it useful.
well... I did reply kind of "jokingly" at first... but now - maybe somebody will make one thing clear for me too... imagine a cell phone... there is a DSP chip in it that performs voice encoding/decoding - lets say the phone is using codec A... there is another cell phone with another DSP chip in it... that one is using codec B (A and B are different coding methods = different codecs) now - imagine a "base station" that the above cell phones are talking to - that base station has to be able to understand both (or n in general) coding techniques - it's done by running different software on the same DSP chip - everything happens "on the fly" - the DSP chip in the base station is dynamicaly choosing which coding technique to use - without reseting the chip of course... oh... and let's say there are only resources to run 1 codec at a time... is there a need for malloc/delete? but then - what do I know? I've never done anything with the cell phones (except using them rarely) or even "wireless technology" in general... so - please - all the specialists out there - does the above example make any sense to you? or is it the other way around? is it the cell-phone rather than the base station that implements multiple codecs? or is there just one standard coding method use for the whole GSM system? and please excuse me my language problems... have a nice day everybody...

Jerry Avins wrote:
(snip regarding malloc() and DSP programming)

> Maybe you can help me to understand how malloc() might be used in an > embedded system. I assume that there is no virtual memory (swapping to > disk) available,
Well, dynamic storage allocation was in use on machines without virtual memory for many years. OS/360 for one example.
> and that the routines to be run use fixed-size arrays and buffers.
Now, this is the question. If they are fixed size static allocation is likely best. (Some non-DSP systems have problems doing large static allocation, but that is a different question.)
> It is never necessary to allocate memory unless it will > also be de-allocated later.
It is also nice when you don't know the size initially, and also don't know the available memory on the machine it will run on. In that case, it may only be deallocated when the program is done. For the DSP case using a C #define so that it can be recompiled with a machine specific size may also work.
> Although I have sometimes needed to use the > same memory space sequentially for different routines, I've never > encountered a situation that prevented me from allocating all the space > I needed at compile time. What would you use malloc() for?
In the old Fortran days EQUIVALENCE was used to give more than one name to the same (statically allocate) storage. That allowed one to conserve memory without making it too ugly. As many Fortran systems only did static allocation, one would declare arrays large enough for the largest case. If the target is a dedicated device with a known amount of storage, and always performing the same function I have to agree that static allocation should be fine. To use memory sequentially for different routines when the size for each is not known at compile time it can still be useful to have malloc(). The original K&R C book (and maybe the second edition) have as an example a malloc() that uses a static array to allocate from. -- glen