예제 #1
0
// realloc: this is a bit more complex. First we identify the correct memory
// pool and try to realloc there. If this doesn't work, we try to realloc in 
// another pool before giving up.
void* _realloc_r( struct _reent* r, void* ptr, size_t size )
{
  void* temp;
  u32 lstart, lend;
  unsigned i = 0;
  size_t prevsize;
  
  // Realloc with ptr == NULL : malloc
  // Realloc with size == 0 : free
  if( !ptr )
    return size ? _malloc_r( r, size ) : NULL;
  else if( !size )
  {
    _free_r( r, ptr );
    return NULL;
  }

  // At this point we know that this is an actual realloc
  // Identify the memory pool
  while( 1 )
  {
    if( ( lstart = ( u32 )platform_get_first_free_ram( i ) ) == 0 )
      return NULL;
    lstart = ( u32 )tlsf_elua_align_addr( ( void* )lstart );
    lend = ( u32 )platform_get_last_free_ram( i );
    if( ( lstart <= ( u32 )ptr ) && ( ( u32 )ptr <= lend ) )
      break;
    i ++;
  }    
  
  // Easy case: realloc succeeds in the same memory pool
  if( ( temp = realloc_ex( ptr, size, ( void* )lstart ) ) != NULL )
    return temp;
  
  // If realloc returned NULL, look for another pool
  prevsize = tlsf_elua_get_block_size( ptr );
  i = 0;
  while( 1 )
  {
    if( ( temp = platform_get_first_free_ram( i ) ) == NULL )
      break;
    temp = tlsf_elua_align_addr( temp );
    if( ( u32 )temp != lstart )
    {
      if( ( temp = malloc_ex( size, temp ) ) != NULL )
      {
        memcpy( temp, ptr, prevsize < size ? prevsize : size );
        free_ex( ptr, ( void* )lstart );
        break;      
      }
    }
    i ++;
  }
  return temp;
}
예제 #2
0
void *nx_realloc(void *ptr, U32 size) {
  void *ret = realloc_ex(ptr, size, mp);
  NX_ASSERT_MSG(ret != NULL, "Out of memory");
  return ret;
}
예제 #3
0
 void * MALLOC_ATTRIBUTE realloc(void * p, std::size_t size)
 {
     scoped_lock lock(data_);
     return realloc_ex(p, size, data_.pool);
 }
예제 #4
0
 void * realloc(void * p, std::size_t size)
 {
     scoped_lock lock(data_);
     return realloc_ex(p, size, data_.pool);
 }
예제 #5
0
 void * MALLOC ASSUME_ALIGNED(32) realloc(void * p, std::size_t size)
 {
     scoped_lock lock(data_);
     return realloc_ex(p, size, data_.pool);
 }
예제 #6
0
void *_realloc_r(void *reent, void *aptr, size_t nbytes) {
//	lazy_initialize();
	return realloc_ex(aptr, nbytes, mem_pool);
//	return realloc_ex(aptr, nbytes, heap_for_domain(TDOM_SELF));
}