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
 How to get rid of temporary Datasets

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
Frank_H Posted - 04/07/2006 : 11:25:03 AM
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!

7   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 04/10/2006 : 5:38:22 PM
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
Frank_H Posted - 04/10/2006 : 09:32:46 AM
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

easwar Posted - 04/07/2006 : 10:39:06 PM
Hi Mike,

Your solution is of course much more elegant!

Thanks,

Easwar
OriginLab


Mike Buess Posted - 04/07/2006 : 5:10:21 PM
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
easwar Posted - 04/07/2006 : 1:25:54 PM
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
easwar Posted - 04/07/2006 : 1:12:02 PM
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
Frank_H Posted - 04/07/2006 : 12:43:22 PM
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


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