Re: [eigen] portable reallocation...

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


So, how about this one (a single handmade version):

inline void* ei_new_handmade_aligned_realloc(void* ptr, size_t size,
size_t old_size)
{
  if (ptr==0)
    return ei_aligned_malloc(size);

  if (size==0)
  {
    ei_aligned_free(ptr);
    return 0;
  }

  void* newptr = ei_aligned_malloc(size,16);
  if (newptr == 0)
  {
    /*errno = ENOMEM;*/ // according to the standard we should set
errno = ENOMEM
    return 0;
  }

  if (ptr != 0)
  {
    std::memcpy(newptr, ptr, std::min(size,old_size));
    ei_aligned_free(ptr);
  }

  return newptr;
}

- Hauke



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/