How to create a dinamic array in kernel function

Hi)I’a C# programmer. I use CUDA.NET library to make a programms in CUDA. I create a simple example of using CUDA. It’s OK. The kernel function is created by C language. I’d like to ask how to create an dinamic array in kenel function because a I have some errors during the compilation. I use MS VS 2008 Professional, Win 7 64bit, GeForce 610M, CUDA 5.0. For example,

global void func(float *g_date)
{
const int n = blockDim.x;
float *a = new float[n];
for(int i = 0; i < n; i++)
a[i] = (float)i;

delete[] a;
//make something with a and g_data

}

And my program crash during execution. Why? Is it a problem in CUDA.NET or CUDA generally doesn’t support it. I’d like to remember that the simple examples is working correctly with CUDA.NET. Please? help. If CUDA.NET don’t work correctly. Does any CUDA librarries exist which use a С#?

Does anybody know it?

If instead of float * a = new float[n] I write float a[n], then I have error “Expression must have a constant value”. I saw the examples. There in header file programmers write #define n 20, then they create an array. But I’d like to create with the help of parameter of the function!!! Please, help. Wtite this function in your project. And see, what happends?

I think dynamic allocation within device code is not a good idea. It is very expensive latency wise. Try allocation larger amount of memory in a form of preprocessing and then manage it with Your own versions of ‘malloc’ and ‘free’ (or ‘new’ and ‘delete’). That what I would do.

A may-be-usefull link below:
[url]http://www.memorymanagement.org/articles/begin.html[/url]

MK