Click here to Skip to main content
14,638,959 members
Rate this:
Please Sign up or sign in to vote.
See more:
		  // printf("pz2nz:%f\n",pz2nz[0][i]);	

here kld_smooth_norm[80,000] and the index1 index2 will be changing for each loop
first loop index1=12612 index2=14521
2nd loop index1=16029 index2 =23753
3rd loop index1=31387 index2= 55794
4th loop index1=62933 index2=68856
and in pz2nz i want to store all the element for each loop from index1 t oindex2
can someone tell me how to declare the size of pz2nz for storing the elements
Rate this:
Please Sign up or sign in to vote.

Solution 1

Don't use an array, use one of the Collection classes[^].

Apologies I misread C for C#. You can make an array dynamic in C by allocating it at run time via malloc[^].

nv3 17-Jan-15 5:55am
Op is talking about C, not C#.
Richard MacCutchan 17-Jan-15 6:05am
Rate this:
Please Sign up or sign in to vote.

Solution 2

There is no way to declare an array in C, the size of which is unknown at compile-time. Instead you can use malloc / free to allocate storage dynamically and assign its address to a pointer.

Allocating storage takes some time and it is advisable to avoid allocating / freeing storage in a high frequency, for example in a loop. In your case that seems to be possible easily: Determine in a first loop the maximum length needed and then allocate that storage once.

Another observation here, is that you seem to use only small index intervals in each loop, for example 62933 ... 68856. In such a case it may pay off to just allocate an array for that index interval, 5924 cells in that case, and recalculate the index with which you access that array.

In C++ the job would be somewhat easier as you could make use of classes like vector, which does much the storage management for you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100