| Author |
Topic  |
|
|
RiverFalls
USA
36 Posts |
Posted - 02/15/2007 : 5:06:34 PM
|
Origin Version (Select Help-->About Origin): 7.5 Operating System: Win XP
I am having trouble with a routine that is causing Origin to crash.
The routine simply searches through a worksheet for a specific condition and adds a row when that condition is true. The worksheet has four columns and 360,000 rows. When I run the routine over a range of about 30,000 rows, it works very well, but for larger ranges, Origin crashes. I suspect that this is a memory problem, but I am not familiar with OriginC enough to know how it is handling the allocation of the memory for the new rows. If I remove the entire ASSERT(wks.InsertRow()) line, the routine runs very fast and does not crash. Removing the ASSERT() command itself and just leaving the wks.InsertRow() portion does not seem to change the behavior.
Any suggestions about what I've done wrong, and how I can fix it?
void AddSkipped(int start,int stop) { WorksheetPage wpg = Project.Pages(); Worksheet wks(wpg.GetName()); Dataset dsA(wks, 0); Dataset dsB(wks, 1); Dataset dsC(wks, 2); Dataset dsD(wks, 3);
uint numpts= 400000; dsA.SetSize(numpts); dsB.SetSize(numpts); dsC.SetSize(numpts); dsD.SetSize(numpts); for(uint i= start;i<=stop;i++) { if( (dsD[i]>4)&&(dsD[i+1]>2) ) { //The ASSERT command is what causes problems ASSERT(wks.InsertRow(i+1)); dsA[i+1]=(dsA[i]+dsA[i+2])/2.0; dsB[i+1]=(dsB[i]+dsB[i+2])/2.0; dsC[i+1]=0; dsD[i+1]=0; } }//end for loop }//end AddSkipped
Thank you, -Lowell
Edited by - RiverFalls on 02/15/2007 6:25:52 PM |
|
|
Mike Buess
USA
3037 Posts |
Posted - 02/16/2007 : 09:23:24 AM
|
Hi Lowell,
I suspect you're correct that it's a memory issue because I can reproduce the crash. The following version of your code appears to be more robust in that it does not crash Origin. However, it's not particularly fast... takes 18min to insert 35000 rows to a 360000 row wks.
void AddSkipped1(uint start,uint stop) { Worksheet wks = Project.ActiveLayer(); double dA,dB; for(uint i=start; i<=stop; i++) { if( (wks.Cell(i,3)>4)&&(wks.Cell(i+1,3)>2) ) { dA = (wks.Cell(i,0) + wks.Cell(i+1,0)) / 2.0; dB = (wks.Cell(i,1) + wks.Cell(i+1,1)) / 2.0; ASSERT(wks.InsertRow(i+1)); wks.SetCell(i+1,0,dA); wks.SetCell(i+1,1,dB); wks.SetCell(i+1,2,0); wks.SetCell(i+1,3,0); } } }
If one of the first two columns is ascending or descending you can do things much faster by adding the interpolated values at the end of the worksheet and sorting the whole wks versus that column. This version takes 15sec to add 35000 rows, sorting against the first column.
void AddSkipped2(uint start,uint stop) { Worksheet wks = Project.ActiveLayer(); double dA,dB; Dataset dsA(wks, 0); Dataset dsB(wks, 1); Dataset dsC(wks, 2); Dataset dsD(wks, 3); for(uint i=start; i<=stop; i++) { if( (wks.Cell(i,3)>4)&&(wks.Cell(i+1,3)>2) ) { dA = (wks.Cell(i,0) + wks.Cell(i+1,0)) / 2.0; dB = (wks.Cell(i,1) + wks.Cell(i+1,1)) / 2.0; dsA.Add(dA); dsB.Add(dB); dsC.Add(0); dsD.Add(0); } } wks.Sort(0); }
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 02/16/2007 09:24:17 AM |
 |
|
|
RiverFalls
USA
36 Posts |
Posted - 02/16/2007 : 10:01:50 AM
|
Mike, That first routine worked very well. It only took 3 minutes to run through the entire worksheet. Thank you for your help. Lowell |
 |
|
| |
Topic  |
|
|
|