#ifndef EIGEN_QTMALLOC_MODULE_H
#define EIGEN_QTMALLOC_MODULE_H

#if (!EIGEN_MALLOC_ALREADY_ALIGNED)

#ifdef QVECTOR_H
#error You must include <Eigen/QtAlignedMalloc> before <QtCore/QVector>.
#endif                                           

#ifdef Q_DECL_IMPORT
  #define Q_DECL_IMPORT_ORIG Q_DECL_IMPORT
  #undef Q_DECL_IMPORT
  #define Q_DECL_IMPORT
#else
  #define Q_DECL_IMPORT
#endif

#include "Core"

#include <QtCore/QVector>

inline void *qMalloc(size_t size)
{
  return Eigen::ei_aligned_malloc(size);
}

inline void qFree(void *ptr)
{
  Eigen::ei_aligned_free(ptr);
}

inline void *qRealloc(void *ptr, size_t size)
{
  void* newPtr = Eigen::ei_aligned_malloc(size);
  memcpy(newPtr, ptr, size);
  Eigen::ei_aligned_free(ptr);
  return newPtr;
}

#endif

#ifdef Q_DECL_IMPORT_ORIG
  #define Q_DECL_IMPORT Q_DECL_IMPORT_ORIG
  #undef Q_DECL_IMPORT_ORIG
#else
  #undef Q_DECL_IMPORT
#endif

#endif // EIGEN_QTMALLOC_MODULE_H
