stevepoole wrote:HI again Tobias,
The TSP uses 9 arrays, and I want to get maximum size on my windows XP PC 1GoRAM.
At Present I have : int x[256], y[256],w[256],a[256],b[256],bes[256],be[256];
double bc[256],ds[256][256)]; I presume I have to use either malloc or calloc with each array.
Which of the two functions would you advise, since my program uses no pointers?
Best wishes,
Steve.
Steve,
first, your declarations have to be slightly re-written and would be changed to
Code: Select all
int *x, *y, *w, *a, *b, *bes, *be;
double *bc, *ds,
Next you would adapt your initialization code (the above just declares the arrdesses, not the memory blocks that will live there). I guess that would happen somewhere early in
main(), before any of the arrays are used - In case you are 100% sure you will never touch any array element that hasn't been initialized in your program explicitly, you can use
malloc - If you aren't, use
calloc, as otherwise your array elements will have random values after initialization. To make your life a little easier when changing array sizes afterwards, define an ARRAYSIZE constant that can easily be changed in one single place
Code: Select all
#define ARRAYSIZE 256
x = malloc (ARRAYSIZE * sizeof (int));
y = malloc (ARRAYSIZE * sizeof (int));
.
.
.
bc = malloc (ARRAYSIZE * sizeof (double));
dc = malloc (ARRAYSIZE * ARRAYSIZE * sizeof (double)); // Note we need ARRAYSIZE^2 bytes!
With regards to sizes:
With ARRAYSIZE set to 256, your arrays will need around 7 * 256 * 4 + 256 * 8 + 256^2 * 8 = ~16k (assuming 32bit Windows versions)
You should be able to at least use 10240 as a size for starters (above formula evaluates to ~1GB in that case) - Actually, windows will allow you to go even beyond physical memory sizes, but will start to work with virtual memory and become slow.... I suppose you'd be starting small and gradually evaluate where you can go.
Regards,
Tobias