mb_malloc

Previous  Next

 

void* mb_malloc( size_t size )

 


 

Allocates a memory block that can be used for variables and strings and arrays in MyBASIC2.  An allocated memory block must be deallocated using the mb_free function.

 

Example

 

// Simple function that returns the string "This is My String!"

 

int _my_func( mb_interpreter_t* s, void** l )

  {

  mb_assert( s && l );

 

  mb_check( mb_attempt_open_bracket( s, l ) );

  mb_check( mb_attempt_close_bracket( s, l ) );

 

  const char* pMyString = "This is My String!";

 

  char* pString = (char*)mb_malloc( strlen( pMyString ) + 1 );

 

  if ( pString )

  {

     strcpy( pString,  pMyString );

  }

 

  mb_check( mb_push_string( s, l, pString ) );

 

  return MB_FUNC_OK;

}