Quantcast
Channel: Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1616

Problem with new'd object and vectorized loops

$
0
0

I am currently trialling the ICL to see what improvements we can make to our software to hopefully speed it up.

I've had quite a lot of issues trying to get it to compile but eventually got there (may raise a few more topics on things I've had to disable to get it to build), it worked fine in debug but in release it crashed at what appeared to be a totally irrelevant place.

It was failing on a loop that was initializing some arrays to zero, but complaining about access violations. I eventually figured out that it must be because of vectorizing the class but it wasn't sure why as we do __declspec(align(16)) before the class so it should be correctly aligned, also we have no problems with this code when compiled with Visual Studio 2013 compiler.

I eventually found the problem in a cutdown testbed version of the code (attached)

It seems when creating an instance of the object like so then it fails:

CModel* pModel = new CModel();

If instead I create it as follows then everything works fine:

	void* ptr = _mm_malloc(sizeof(CModel), 16);
	CModel* pModel = new(ptr) CModel();

So, it's possible (likely) that my knowledge of C++ is lacking at that there is another way I am supposed to create a new instance of an object when new'ing (the class CModel actually is a base class so hence the need for pointer) but just asking for clarity as this was a real pain to try and figure out what was going wrong as the pointer was fine and the error it was throwing seemed totally irrelevant until I twigged that it must be vectorizing the loop (I've been reading up on it).

AdjuntoTamaño
DescargarTestApp_0.zip6.9 KB

Viewing all articles
Browse latest Browse all 1616

Trending Articles