Sign in

username:

password:



Not a member?

Search c6x



Search tips

Subscribe to c6x



c6x by Keywords

AD535 | BIOS | Booting | Bootloader | C621 | C6211 | C6415 | C671 | C6711 | C6711DSK | C6713 | CCS | Chassaing | COFF | DAT | DM64 | DM642 | DMA | DSK671 | DSK6711 | EDM | EDMA | EMIF | Emulator | EVM | EVM620 | FFT | FIR | GPIO | Halting | HPI | HWI | IDK | JTAG | LDB | LDH | LDW | Linker | LMS | LOG_printf | Matlab | McBSP | MEM_alloc | MIPS | PCI | PCM3003 | Pipeline | Profiling | QDM | Reset | ROM | RTDX | Sampling | SDRAM | Stack | TEB | THS1206 | TMS320C621 | TMS320C6416 | TMS320C6711 | TMS320C6713 | UART | Vector Table | XBUS | XDS560


Discussion Groups

See Also

Embedded SystemsFPGAElectronics

Discussion Groups | TMS320C6x | memory allocate

Technical discussions about the TI C6000 DSPs (including the c62x, c64x and c67x DSPs).

  

Post a new Thread

memory allocate - fx-7413 - Jul 28 12:31:28 2010

hello!
i'm using CCS3.1 and C6416, in my project, i want to allocate space for each
pointer of a ' **g_apbyTxBuf ' tpye array, i did like this:
Uint8 *g_apbyTxBuf[40];
.........
Bool AllocateTxBuf()
{
 int i,j;
 for(i = 0; i < TX_BUF_NUM; i++)
 {
  g_apbyTxBuf[i] = NULL;
  g_apbyTxBuf[i] = (Uint8 *)malloc(TX_BUF_LEN * sizeof(Uint8));
  j = sizeof(g_apbyTxBuf[i]);
  LOG_printf(&trace,"%d",j);
  if(g_apbyTxBuf[i] == NULL)
  {
   LOG_printf(&trace,"BUF_allc failed!");
   SYS_abort("BUF_allc failed");    ********************
   return FALSE;
  }   
 } 
 LOG_printf(&trace,"allocation successful!");
 return TRUE;
}
 
when i run the project, i use the 'go main' mode, the program abort at the line
with '***********************', i'm puzzled, why the value of g_apbyTxBuf[i] is
still NULL?
and i use sizeof to check the length of g_apbyTxBuf[i], that is j, the value is
j=4.
so i cannot work out the reason.
could there anyone help me? thx a lot
______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )

Re: memory allocate - Richard Williams - Jul 29 2:38:26 2010

fx,

Answers to your questions: where my answer is prefixed with '<rkw>'

> when i run the project, i use the 'go main' mode, the program abort at 
> the line with '***********************', 

<rkw> are you running with the BIOS or without the BIOS?
I suspect 'without the BIOS', so the program has no where to return to when
SYS-Abort() 
is called, so probably executes a 'halt' instruction.
Have you used the CCS to display a interleaved listing of the source+assembly?
Then you would know exactly what instruction caused the program halt.
> i'm puzzled, why the value of g_apbyTxBuf[i] is still NULL? 

<rkw> the call to malloc() returns NULL when the allocation fails.
That is why g_apbyTxBuf[i] is NULL.
What was the value of 'i' when the program fails?
Did you allocate a heap in the project parameters or the .cmd file, large enough
to 
contain all the area that malloc() needs?

> i use sizeof to check the length of g_apbyTxBuf[i], that is j, the value is
j=4. 

<rkw> the 'thing' being passed to the sizeof() function is a single item
in the array 
g_apbyTxBuf, not the size of the area pointed to by the pointer within that
item.
A pointer is 4 bytes.  That is why the value in 'j' is 4.
Note:
--You already know the size of the malloc'd area is either 0 (when NULL returned
by 
malloc()) or is 'TX_BUF_LEN * sizeof(Uint8)'
--There is no way for the code to find the size of the area returned by
malloc()
R. Williams

---------- Original Message -----------
From: fx-7413 <f...@163.com>
To: c6x <c...@yahoogroups.com>
Sent: Wed, 28 Jul 2010 17:44:43 +0800 (CST)
Subject: [c6x] memory allocate

> hello!
> i'm using CCS3.1 and C6416, in my project, i want to allocate space 
> for each pointer of a ' **g_apbyTxBuf ' tpye array, i did like this: 
> Uint8 *g_apbyTxBuf[40]; ......... 
Bool AllocateTxBuf() 
{ 
int i,j; 

for(i = 0; i < TX_BUF_NUM; i++) 
{  
    g_apbyTxBuf[i] = NULL;  
    g_apbyTxBuf[i] = (Uint8 *)malloc(TX_BUF_LEN * sizeof(Uint8));  
    j =  sizeof(g_apbyTxBuf[i]);  
    LOG_printf(&trace,"%d",j);  

    if(g_apbyTxBuf[i]  == NULL)  
    {   
        LOG_printf(&trace,"BUF_allc failed!");   
        SYS_abort("BUF_allc failed");    ********************   
        return FALSE;  
    }  // endif( malloc failed ) 
 
} // end for( each buffer ) 

LOG_printf(&trace,"allocation successful!"); 
return TRUE; 
}
> 
> when i run the project, i use the 'go main' mode, the program abort at 
> the line with '***********************', i'm puzzled, why the value of 
> g_apbyTxBuf[i] is still NULL? and i use sizeof to check the length of 
> g_apbyTxBuf[i], that is j, the value is j=4. so i cannot work out the
reason.
> could there anyone help me? thx a lot
------- End of Original Message -------

_____________________________________

______________________________
New Code Sharing Section now Live on DSPRelated.com. Learn about the Reward Program for Contributors here.



(You need to be a member of c6x -- send a blank email to c6x-subscribe@yahoogroups.com )