Aligned operator new support in Intel C++ Compiler

Version:

  • Intel(R) Parallel Studio XE 2015 Composer Edition for C++
  • Intel(R) Parallel Studio XE 2015 Professional Edition for C++

Operating Systems: Windows; Linux; OS X*

Feature Details:

The new released Intel(R) C++ Compiler XE 15.0 in Intel® Parallel Studio XE 2015 Composer Edition for C++ Windows* and Linux* supports the aligned operator"new".

A new header "aligned_new" is provided by the Intel® Parallel Studio XE 2015 Composer Edition for C++ Window* and Linux*

To use the aligned operator new, just include the new header "aligned_new". For example:

#include <cstdint>
#include <cassert>
#include <aligned_new>
using namespace std; 

struct alignas(64) Test
{
    Test() {
        assert((intptr_t)this%64 == 0); 
    }
};  

Test* foo()
{
	Test *p = new Test();
	return p;
}

Note: the support on OS X* has been added in Intel(R) Parallel Studio XE 2015 Composer Edition for C++ update 1.

For more complete information about compiler optimizations, see our Optimization Notice.

1 comment

Top
Antony P.'s picture

Hi,

Unfortunately your implementation on Windows has a bug in the _ALIGNED_FREE macro and never actually deletes the aligned memory.  On Windows _ALIGNED_FREE is implemented as such:

    #define _ALIGNED_FREE(p)  _aligned_free

If you look closely this never passes the arguments of the macro to the function, and as such when you look at the disassembly for the function you can verify that no call instruction is generated for the _aligned_free function.  Additionally if you run the code sample on this page through Intel Inspector it correctly flags this as a memory leak.  The correct implementation for this macro is as such:

    #define _ALIGNED_FREE(p)  _aligned_free(p)

Note the Linux version of this macro is correctly implemented so does not feature this memory leak.  This is easy to fix on my local install; however code I write using this feature will have a memory leak for anyone else compiling my code who has not corrected the mistake in their local version of the <aligned_new> header.  As such it would be good to see this fixed at the compiler level.

Kind regards,

Antony

 

 

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.