The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 ASSERT(wks.InsertRow()) causing crash

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
RiverFalls 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
2   L A T E S T    R E P L I E S    (Newest First)
RiverFalls 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
Mike Buess 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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000