#Realloc Problem
Hi Jonas,
Does IPAS3 have a problem with using realloc?
The reason I ask is that I'm trying to dynamically expand arrays and structures
as
more triangles are generated. When performing reallocs on structures I define
inside my code, there's no problem. However, when I try and use realloc on
XVData and XFData structures, I get memory protection faults.
Here's a sample of the code I'm using:
XVData *vertdata;
int pmax;
int psize;
…
/* allocate memory for vertex assignment table */
pmax = 1000;
psize = 0;
vertdata = malloc(pmax * sizeof(XVData));
if (vertdata == NULL){
sprintf(message, "Abort! Insufficient memory for vertices.");
gfx_prompt(message);
return 0;
}
…
/* allocate more memory for the vertex assignment table */
for (i = 0; i < vsize; i++) {
++psize;
if(psize > pmax){
/* table not big enough, expand it */
pmax = pmax + 100;
vertdata = realloc(vertdata, pmax * sizeof(XVData));
if (vertdata == NULL){
sprintf(message, "Abort! Insufficient memory for vertices.");
gfx_prompt(message);
return 0;
}
}
Is this problem caused by the structure residing in far memory or is it
something
else? Should I be using farrealloc? As always, any help would be appreciated.
BTW, What's the status of the MESH_SELECTED question I posted?
Thanks,
Danny…