I know there are:
& cast-expression
* cast-expression
And you can do things like:
But somehow i have memory allocation problems.
I have a multidimensional array like:
Code:
┌──────┬──────┬──────┐
│string│string│string│ <= headers
├──────┼──────┼──────┤
│string│string│string│ <= cells
├──────┼──────┼──────┤
│string│string│string│ <= cells
└──────┴──────┴──────┘
but instead of strings i use classes and structures
PHP Code:
enum TColTypes { ctString, ctInteger, ctTime };
typedef struct Header {
TColTypes Type;
short Width;
char *Text;
} * PHeader;
typedef struct Cell {
char *Text;
} * PCell;
class GridRow
{
private:
Cell **Cells;
}
class Grid
{
private:
Header **Headers;
GridRow **Rows;
}
as you can see it has an array of headers like:
PHP Code:
Headers[0] = new Header;
and an array of rows that contains cells
PHP Code:
Rows[0] = new GridRow;
Rows[0]->Cells[0] = new Cell;
But whenever i try to realloc() the size of Headers and it seems i'm forced to recreate tmpHeaders and copy the data from Headers.
Sadly this is not an option because it could deal with 100MB of data and then it will be a pain and slow process.
So i've tried to use the following which somehow fails to copy the data properly.
PHP Code:
void __fastcall Grid::SetColCount(int Value)
{
if (Value < 0) Value = 0;
if (Value != fColCount) {
// Destroy header collumns if the size gets less
if (Value < fColCount) {
for (int c=Value; c<fColCount; ++c) { delete Headers[c]; }
}
// A pointer has sizeof = 4
Headers = (Header **)realloc(Headers, Value * 4); // <= issue here due to ** ?
// Create header collumns if the size gets bigger
if (Value > fColCount) {
for (int c=fColCount; c<Value; ++c) { Headers[c] = new Header; }
}
fColCount = Value;
}
}
I use pointers instead of something like: Header *Headers[10]; because it is very dynamic and column swapping also occures.
Could someone explain me what goes wrong ?