Dynamic memory allocation

Hi,

i want to alloc an array using an int uniform variable:

uniform int num;

float A[num];

but i get the error C1307: non constant expression for array size

How can i solve it?

Can you give an high level overview of what you want to do ?
What will be stored in the array ? How ?

If you have a idea of the maximum you will use for num, and if it is not too big, you can do :

uniform int num;

float A[20]; // maximum possible value for num

then you will only use the array up to num elements.

Thanks for your reply.

Can you give an high level overview of what you want to do ?

I want to implement the K-Nearest Neighbor (KNN) algorithm at the vertex shader. I have stored the vertices into a texture buffer object and have used a uniform variable for the number of vertices.

What will be stored in the array ? How ?

I store the eucledean distances between the current vertex and the rest ones.

If you have a idea of the maximum you will use for num, and if it is not too big, you can do :

uniform int num;

float A[20]; // maximum possible value for num

then you will only use the array up to num elements.

At first, i implemented it using this way but i was wondering if there is a better solution…? :slight_smile:

In terms of dynamic memory allocation, Cg offers parameter arrays that can be sized by the runtime, for what that’s worth to you (mighty slick when combined with interfaces, btw).

And NV’s bindless graphics opens a door to a new universe of possibilites w.r.t to data structures. See the thread in the advanced forum for details.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.