This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

malloc and two dimensional array ( char * * )

I want to allocate memory which I can use as a two dimensional array. But the following code is not working

unsigned char xdata ** memo;
unsigned char i = 0;
// n is number of rows
// size is number of columns
memo = (unsigned char xdata **) malloc( n*2 );
for ( ; i < size; i++)
	memo[i] = (unsigned char xdata *)malloc( size );
this code was inspired from
C++ new operator
memo = new char * [n];
for (int i=0; i < n; i++)
	memo[i*2] = new char [size];
Can you help me resolving this problem? Is there any problem with the logic?

PS: Fairly large memory has been allocated using init_mempool().

Parents
  • "I think you people want to avoid malloc at all costs"

    As already noted, that is generally a good approach for embedded systems suited to an 8051

    What you're doing is not a conventional embedded system for an 8051, and dynamic allocation may well be appropriate to your application - but you hadn't described the application before, so we couldn't tell, could we?

    Too many people just assume that anything a PC can do will be good on an 8051.

Reply
  • "I think you people want to avoid malloc at all costs"

    As already noted, that is generally a good approach for embedded systems suited to an 8051

    What you're doing is not a conventional embedded system for an 8051, and dynamic allocation may well be appropriate to your application - but you hadn't described the application before, so we couldn't tell, could we?

    Too many people just assume that anything a PC can do will be good on an 8051.

Children
No data