|
-
May 25th, 2001, 03:39 PM
#1
Thread Starter
Member
need ideas
Hello all,
I am creating my own custom grid control and I need some ideas. I have created grids in the past that store all the cells in a big array and everytime that a column or row is added/removed/moved I have to create a new array (smaller or bigger than the original) loop through the original and copy its contents to the new array, deallocate the memory used by the original array and then set the original to the new. Does that make sense? Here's an example:
Code:
void AddCol()
{
CELLSTRUCT* pTemp = new CELLSTRUCT[(m_nColCount + 1) * m_nRowCount];
if (m_pCells)
{
for (int row = 0; row < m_nRowCount; row++)
{
for (int col = 0; col < m_nColCount; col++)
{
pTemp[col + (row * m_nColCount)] = m_pCells[col + (row * m_nColCount)];
}
}
delete[] m_pCells;
}
m_nColCount++;
m_pCells = pTemp;
}
While this method definitely works, it seems a bit ineffecient. What I want to know is:
Does anyone else know a better, more effecient method of maintaining grid data? Anyone know how some of the more advanced grids work, like the grid SQL Server Enterprise Manager uses? Thanks for any help/ideas...
Rippin
-
May 25th, 2001, 05:34 PM
#2
Monday Morning Lunatic
Linked lists are probably out in force for things like that, allowing your pseudo-2D-array to have jagged edges (it's not rectangular, each row has a different number of columns contained in it).
Look at the STL container classes...they do everything you need.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|