I am testing Intel MKL, and it looks like they have their own memory management (C-style).
They suggest using their MKL_malloc / MKL_free pairs for vectors and matrices, and I don't know what a good way to handle this. One reason for this is that it is recommended to be at least 16 bytes for memory alignment, and this is explicitly stated with these procedures.
I used to rely on auto_ptr and boost :: smart_ptr to forget about clearing memory.
How can I write an exception-safe program with MKL memory management, or should I just use regular auto_ptr and not bother?
Thanks in advance.
EDIT
http://software.intel.com/sites/products/documentation/hpc/mkl/win/index.htm
this link may explain why I raised the question
UPDATE
I used the idea from the answer below for the dispenser. This is what I have now:
template <typename T, size_t TALIGN=16, size_t TBLOCK=4>
class aligned_allocator : public std::allocator<T>
{
public:
pointer allocate(size_type n, const void *hint)
{
pointer p = NULL;
size_t count = sizeof(T) * n;
size_t count_left = count % TBLOCK;
if( count_left != 0 ) count += TBLOCK - count_left;
if ( !hint ) p = reinterpret_cast<pointer>(MKL_malloc (count,TALIGN));
else p = reinterpret_cast<pointer>(MKL_realloc((void*)hint,count,TALIGN));
return p;
}
void deallocate(pointer p, size_type n){ MKL_free(p); }
};
If anyone has any suggestions, feel free to do it better.
source
share