Yeah, I have found !
I use malloc and realloc functions and this works good. I have try the templates and singletons, but I have compilations bugs...
So here is the code, in C, which can be adapted for all you want...
French version (comments and console text):
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
// allocation
int nbrL = 530;
int nbrC = 1024;
int ** Array2D = (int **)malloc(nbrL*sizeof(int));
void AllocArrays(void)
{
int v = 0;
for(v = 0; v < nbrL; v++)
{
Array2D[v] = (int *)malloc(nbrC*sizeof(int));
}
}
void ReallocArrays(int nbl, int nbc);
int main()
{
AllocArrays();
Array2D[10][14] = 512;
printf("Valeur de la case (10,14) du tableau : %ld n",Array2D[10][14]);
system("PAUSE");
printf("Reallocation en cours...n");
ReallocArrays(253,169);
Array2D[56][169] = Array2D[10][14];
printf("Valeur originale (10,14) :%ld et valeur nouvelle(56,169) : %ld n",Array2D[10][14],Array2D[56][169]);
system("PAUSE");
free(Array2D);
return 0;
}
void ReallocArrays(int nbl, int nbc)
{
//reallocation
int nbL = nbl;
int nbC = nbc;
Array2D = (int**)realloc(&Array2D,nbL*sizeof(int));
for(int i = 0; i < nbL; ++i)
{
Array2D[i] = (int *)malloc(nbC*sizeof(int));
}
}
And English version (comments and console text):
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
// allocation
int nbrL = 530;
int nbrC = 1024;
int ** Array2D = (int **)malloc(nbrL*sizeof(int));
void AllocArrays(void)
{
int v = 0;
for(v = 0; v < nbrL; v++)
{
Array2D[v] = (int *)malloc(nbrC*sizeof(int));
}
}
void ReallocArrays(int nbl, int nbc);
int main()
{
AllocArrays();
Array2D[10][14] = 512;
printf("Cell (10,14) value of Array2D : %ld n",Array2D[10][14]);
system("PAUSE");
printf("Reallocating...n");
ReallocArrays(253,169);
Array2D[56][169] = Array2D[10][14];
printf("First value of cell (10,14) :%ld and new value of cell (56,169) : %ld n",Array2D[10][14],Array2D[56][169]);
system("PAUSE");
free(Array2D);
return 0;
}
void ReallocArrays(int nbl, int nbc)
{
//reallocation
int nbL = nbl;
int nbC = nbc;
Array2D = (int**)realloc(&Array2D,nbL*sizeof(int));
for(int i = 0; i < nbL; ++i)
{
Array2D[i] = (int *)malloc(nbC*sizeof(int));
}
}
It is a console application.
And I have found the problem with gcc: the options were not adapted to a C++ dll
Thank you very much for your help
@+
RTS game project : 3.2% finished
|||%