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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 How to get rid of temporary Datasets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Frank_H

Germany
Posts

Posted - 04/07/2006 :  11:25:03 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5SR6
Operating System: XP

Dear all!

I am using temporary curves generated from temporary Datasets for my data analysis as some analysis functions work only on curves and not on vectors. But I can't get rid of the temporary Datasets afterwards! Try the following code:

void CreateTempCurve(Curve & crv)
{
Dataset ds1,ds2,ds3,ds4;
ds1.Create(10,1);
ds2.Create(10,1);
ds1.Data(0,10);
ds2.Data(0,10);
string name1,name2;
ds1.GetName(name1);
ds2.GetName(name2);
crv.Attach(name1,name2);
}

void test()
{
Curve crv;
Dataset ds3,ds4;
string name;
crv.GetName(name);
//gl.AddPlot(crv,IDM_PLOT_LINE);
crv.Destroy();
if(ds3.Attach(name))
{
printf("Dataset %s is still there!\n",name);
ds3.Destroy();
if(ds4.Attach(name))
printf("And Dataset %s still lives!\n",name);
else printf("Now Dataset %s is dead\n",name);
}
else printf("Now Dataset %s is dead\n",name);
}

Calling test reveals, that although I destroy the curve and even after attaching a dataset again to my temporary dataset and destroying it afterwards I can't get rid of temporary datasets generated in my CreateTempCurve function. Seems the Destroy method works only if called within the same (function) level as the Create method. This generates an annoying memory leak.
Any suggestions?

Cheers,
Frank

P.S.: I just tested and found that the temporary datasets are saved together with the Origin Project. So they also fill my Harddisk!

Frank_H

Germany
Posts

Posted - 04/07/2006 :  12:43:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Just wanted to let you know my solution (a workarround, not perfect):
I now have a dedicated hidden worksheet for my temporary datasets and some functions which add and delete datasets to/from this worksheet.

I still would like to know how to delete the about 300 datasets named TEMP_xxx from my project.

Cheers,
Frank

Go to Top of Page

easwar

USA
1965 Posts

Posted - 04/07/2006 :  1:12:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Frank,

As you know, the curve object has multiple constructors, some of which simply create a curve that attaches to existing datasets, and some of which create a copy of the datasets in the process of creating the curve.

If the curve is created by attaching to existing datasets as is your case (whether the dataset was in a wks or was created using dataset create method), destroying the curve does not destroy the datasets.

On the other hand if the curve was created such that it made a copy during the curve creation, then destroying the curve destroys those copies.

This can be seen from the following code: Start a new project which has just one wks with two columns and run this code:


void test_curve()
{
Worksheet wks = Project.ActiveLayer();
if( !wks ) return;

out_str("\nList of datasets at the beginning:");
LT_execute("list -s;");

// Attach a curve object to wks col - this curve is not a copy
Curve crv1(wks, 0 , 1);
out_str("\nList of datasets with attached curve:");
LT_execute("list -s;");

// Destroy curve - this does not destroy datasets!
crv1.Destroy();
out_str("\nList of datasets after ""destroying"" attached curve:");
LT_execute("list -s;");

// Now create a copy curve - curve.create has multiple methods
Dataset dsX(wks, 0);
Dataset dsY(wks, 1);
Curve crv2(dsX, dsY); // this is a copy curve
out_str("\nList of datasets with copy curve:");
LT_execute("list -s;");

// Now destroy copy curve - this does destroy the copied x, y datasets
crv2.Destroy();
out_str("\nList of datasets after ""destroying"" copy curve:");
LT_execute("list -s;");
}



So in your case, you should create the datasets themselves in the main function and pass them to a second function to fill them, instead of passing the curve - because you do need to destroy the datasets themselves. Or you can use a solution such as a hidden wks that you came up with).

Now, to delete all these TEMP_xxx datasets...we will post a separate solution...

Easwar
OriginLab


Edited by - easwar on 04/07/2006 1:12:25 PM
Go to Top of Page

easwar

USA
1965 Posts

Posted - 04/07/2006 :  1:25:54 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:

I still would like to know how to delete the about 300 datasets named TEMP_xxx from my project.




Hi Frank,

There may be more elegant ways, but here is a crude way that works - you can run this one time and get rid of them and save your OPJ again
1> go to script window and type
list -s
to list all datasets, which would list also the temp_xxx datasets
2> note the max number of the temp_xxx say it is 320
3> compile the following function and run it such as
remove_temp 320

Hope this helps.
(keep a backup of your OPJ just in case some other real data with name temp_ exist, and then check to make sure the right things got deleted - don't want you to lose any of your work!)

Easwar
OriginLab


void remove_temp(int num)
{
// This is a crude solution!
for(int i = 0; i <= num; i++)
{
string str;
str.Format("TEMP_%d", i);
Dataset ds(str);
if( ds )
{
out_str(str);
string strCMD;
strCMD.Format("delete %s;", str);
LT_execute(strCMD);
}
}
}





Edited by - easwar on 04/07/2006 1:30:54 PM
Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/07/2006 :  5:10:21 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Frank,

This will delete all datasets that are not attached to a worksheet...

LT_execute("del -as");

Cautions similar to those raised by Easwar apply to its use.

Mike Buess
Origin WebRing Member
Go to Top of Page

easwar

USA
1965 Posts

Posted - 04/07/2006 :  10:39:06 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Mike,

Your solution is of course much more elegant!

Thanks,

Easwar
OriginLab


Go to Top of Page

Frank_H

Germany
Posts

Posted - 04/10/2006 :  09:32:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Easwar, Hi Mike

Thanks for your help! I probably should read further into the LabTalk documentation - at the moment I try to do everything with OriginC.

Easwar, I still wonder: The Destroy() method generally destroys only Datasets which I generated on the current scope and does not generate ones to which I just attached using Attach(name) ?
Is it generally the case, that Destroying objects from the "Internal Origin Objects" group destroys the object represented while destroying "Composite Data Types" objects does not destroy the attached object?
Then of cause my problem arose from the fact that there is no "Internal Origin Object" representing unattached Dataset.

Cheers,
Frank

Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 04/10/2006 :  5:38:22 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Then of cause my problem arose from the fact that there is no "Internal Origin Object" representing unattached Dataset.
Hi Frank,

That's not to say that Origin C has no control over unattached datasets. Project::LooseDatasetNames will pick out their names and you can then attach & manipulate or delete with LT_execute("del " + datasetName). For example, the following test() function is somewhat more discriminating than LT_execute("del -as") in that it deletes all unattached datasets whose name starts with TEMP...
void test()
{
StringArray sa;
get_loose_datasets(sa,"TEMP");
for(int i=0; i<sa.GetSize(); i++)
LT_execute("del " + sa[i]);
}

void get_loose_datasets(StringArray& sa, string baseName = "")
{
string str;
for(int i=0; i>=0; i++)
{
try
str = Project.LooseDatasetNames(i);
catch( int iErr )
break;
if( str.Find(baseName)==0 )
sa.Add(str);
}
}
Note that I'm using the term "attach" in both the Origin C sense (Composite Data Types) and the "belonging to a worksheet column" (Internal Data Types) sense. However, I think the two meanings amount to the same thing as far as your original problem is concerned.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 04/10/2006 5:53:54 PM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000