How do I create an array in an amp restricted function?

I'm using VC++11 and would like to know how I can create an array of arbitrary length in an amp restricted function:

void mystruct::memberfun(unsigned int size) restrict(amp)
  int arr1[size]; // ERROR Expression must have a constant value
  int arr2[10]; // ok, but I don't want it to be constant!
I'm not sure if the AMP restriction allows this, but try dynamic allocation:

int *arr1 = new int[size];
Were you expecting line 3 to work with Visual C++?

While GCC lets you do that, as it supports C99's variable length arrays, this is one language feature where Visual C++ has always agreed with the Ansi C++ standard: that the size of an array must be const, unless it's dynamically allocated.

From what I've seen, the AMP retrictions say nothing about operator new. So plexus suggestion should be fine, though std::vector would be better (which I've seen it used the AMP samples.)

Last edited on
You cannot "new" anything in amp restricted functions unfortunately...

Were you expecting line 3 to work with Visual C++?

No, I'm grasping at straws. I've tried asking over at the MSDN forums but they don't seem to actually respond to questions.

Vectors are completely forbidden, as are concurrrency::array constructors. As far as I can tell it's not possible to declare arrays of arbitrary length on the accelerator, which is somewhat of a crippling restriction.

If anyone finds anything to the contrary please do post back!
That function is not amp-restricted, so it won't work either. I think you just can't do it... It's ok because there are ways of working around it, but it's quite cumbersome.
Topic archived. No new replies allowed.