Qt-interest Archive, March 2008
Memory problems using QList
Message 1 in thread
Hi everyone,
I have a class named JSSCell and want to create a list of JSSCell objects. I read from a file using QTextStream and put some float values on each cell object. The problem is that the first few objects are allocated correctly, then I get a segmentation fault or malloc() error...
Is there another way to implement this? Or a parameter on GCC to use more heap memory? I am quite new to C++ and maybe it's my mistake...
I'm using Linux (openSuse 10.2), KDevelop and Qt4.
Sorry about the long message and thanks for any help!
Marcos
-- This is the JSSCell constructor
-- It creates an array for the variables (float data)
JSSCell::JSSCell(int id, int shape, int variables, int time)
{
cellID = id;
cellShape = shape;
cellVariables = variables;
cellSimTime = time;
cellVarData = new float(cellVariables * cellSimTime);
initialized = TRUE;
}
-- This is how I created the cell list
QList<JSSCell *> JSSCellData;
for(int i = 0; i < cellquantity; i++)
{
JSSCellData.append(new JSSCell(i, shape, variables, time));
}
-- This is where I get the error...
-- the variables value comes from the file (= the amount of "lines per cell object" on the list)
#define index(cols, rows, numcols) (cols * numcols) + rows
int cellcounter = 0;
while(!JSSinput.atEnd())
{
for(int lines = 0; lines < variables; lines++)
{
buffer = JSSinput.readLine();
values = buffer.split(";");
for(int columns = 0; columns < values.size(); columns++)
{
JSSCellData.at(cellcounter)->setCellVarData(index(columns, lines, time), values.at(columns).toFloat());
}
}
cellcounter++;
}
Abra sua conta no Yahoo! Mail, o único sem limite de espaço para armazenamento!
http://br.mail.yahoo.com/
--
[ signature omitted ]
Message 2 in thread
On Wed, Mar 5, 2008 at 9:35 PM, Marcos Aires Marchesini
<marcosmarchesini@xxxxxxxxxxxx> wrote:
> cellVarData = new float(cellVariables * cellSimTime);
Did you mean to instantiate an array here?
--
[ signature omitted ]