G
Gregory.A.Book
I'm working with displaying and manipulating very large image sets. The
program handles anything from 2D images to 4D RGB volumes in a
time-series. I've been using dynamically allocated arrays to accomplish
this, but having recently added the ability to load and display 4D
data, I've run into some significant performance issues.
For a dataset of size 256x176x176x1, it takes about 30 seconds to
allocate the array. Loading the data into the array from 176 files only
take a few seconds. Accessing the array is fine, I'm able to loop
through the entire volume in a couple seconds. When its time to
deallocate the memory, it takes a couple minutes. This is on a P4
2.4GHz with 1GB RAM. I'm using the code below to allocate and
deallocate the memory.
I've read about alternate methods for multidimensional arrays,
including templates. I've also read about memory pools, but haven't
seen anything about how to allocate a multidimensional array inside of
the pool. I also dont think a pool is ideal because I'll only be
(de)allocating memory when the user program loads or unloads a dataset.
I've also thought about just declaring a single array in memory and
accessing elements by multiplication (ie array[row*col*plane])
What method would be best to quickly allocate and deallocate large
chunks of memory?
Thanks,
Greg
-------------- DECLARATION -----------------
unsigned short int ****imgDataINT16U; /* unsigned 16-bit */
--------------- ALLOCATION -------------------
int i, j, k;
/* setup the image buffer */
imgData->imgDataINT16U = new unsigned short int***[YSize];
for (i=0; i < YSize;i++)
imgData->imgDataINT16U = new unsigned short int**[XSize];
for (i=0; i < YSize;i++) {
for (j=0; j < XSize;j++)
imgData->imgDataINT16U[j] = new unsigned short int*[ZSize];
}
for (i=0; i < YSize;i++) {
for (j=0; j < XSize;j++)
for (k=0; k < ZSize;k++)
imgData->imgDataINT16U[j][k] = new unsigned short int[TSize];
}
--------------- DEALLOCATION -------------
for (i=0; i < imgInfo->GetVolumeYSize();i++) {
for (j=0; j < imgInfo->GetVolumeXSize();j++)
for (k=0; k < imgInfo->GetVolumeZSize();k++)
delete[] imgDataINT16U[j][k];
progDlg.Update(i,"Unloading Data");
}
for (i=0; i < imgInfo->GetVolumeYSize();i++) {
for (j=0; j < imgInfo->GetVolumeXSize();j++)
delete[] imgDataINT16U[j];
}
for (i=0; i < imgInfo->GetVolumeYSize();i++)
delete[] imgDataINT16U;
delete[] imgDataINT16U;
------------ GENERAL ACCESS ------------
voxelValue = imgData->imgDataINT16U[col][row][slice][0];
program handles anything from 2D images to 4D RGB volumes in a
time-series. I've been using dynamically allocated arrays to accomplish
this, but having recently added the ability to load and display 4D
data, I've run into some significant performance issues.
For a dataset of size 256x176x176x1, it takes about 30 seconds to
allocate the array. Loading the data into the array from 176 files only
take a few seconds. Accessing the array is fine, I'm able to loop
through the entire volume in a couple seconds. When its time to
deallocate the memory, it takes a couple minutes. This is on a P4
2.4GHz with 1GB RAM. I'm using the code below to allocate and
deallocate the memory.
I've read about alternate methods for multidimensional arrays,
including templates. I've also read about memory pools, but haven't
seen anything about how to allocate a multidimensional array inside of
the pool. I also dont think a pool is ideal because I'll only be
(de)allocating memory when the user program loads or unloads a dataset.
I've also thought about just declaring a single array in memory and
accessing elements by multiplication (ie array[row*col*plane])
What method would be best to quickly allocate and deallocate large
chunks of memory?
Thanks,
Greg
-------------- DECLARATION -----------------
unsigned short int ****imgDataINT16U; /* unsigned 16-bit */
--------------- ALLOCATION -------------------
int i, j, k;
/* setup the image buffer */
imgData->imgDataINT16U = new unsigned short int***[YSize];
for (i=0; i < YSize;i++)
imgData->imgDataINT16U = new unsigned short int**[XSize];
for (i=0; i < YSize;i++) {
for (j=0; j < XSize;j++)
imgData->imgDataINT16U[j] = new unsigned short int*[ZSize];
}
for (i=0; i < YSize;i++) {
for (j=0; j < XSize;j++)
for (k=0; k < ZSize;k++)
imgData->imgDataINT16U[j][k] = new unsigned short int[TSize];
}
--------------- DEALLOCATION -------------
for (i=0; i < imgInfo->GetVolumeYSize();i++) {
for (j=0; j < imgInfo->GetVolumeXSize();j++)
for (k=0; k < imgInfo->GetVolumeZSize();k++)
delete[] imgDataINT16U[j][k];
progDlg.Update(i,"Unloading Data");
}
for (i=0; i < imgInfo->GetVolumeYSize();i++) {
for (j=0; j < imgInfo->GetVolumeXSize();j++)
delete[] imgDataINT16U[j];
}
for (i=0; i < imgInfo->GetVolumeYSize();i++)
delete[] imgDataINT16U;
delete[] imgDataINT16U;
------------ GENERAL ACCESS ------------
voxelValue = imgData->imgDataINT16U[col][row][slice][0];