auto_ptr

Hi!
Wer hat Erfahrung mit std::auto_ptr in c++
kann man es global deklarieren wie…
Entwicklungsumgebung ist c++builder6

std::auto_ptrlist(new TStringList());

Hier z.B wurde es verwaltet:
bool function(){
//I filled it with texts out of a file
list->Add(…);
return true;
}
//Here in reset(), I do empty the contents. This is always used
//when the application is being broken up without running till the end.
void reset(bool){
if (list->Capacity > 0)
list->Clear()
}
//Here, I called it and this inner-method is implemented in
//another form
void outsidefunction(){
output(list.get());
}

output(TStringList* list){
for (int i = 0; i Count; i++)
//give out the data…
}

Wenn ja, wann wird den Speicherplatz aufgeräumt? Ich muss es global deklarieren, denn ich brauche es im ganzen Programm (Form1 z.B) und auch in anderen Forms (wie Form2, Form3). Ich weiss nicht genau, wann das verwaltet wird und wann oder ob noch andere Applikation es braucht.

Gibt es eine Lösung dazu?

Danke im Voraus
Harp

Als Grundregel kannst du dir merken, dass Speicher mit dem Durchlaufen des Destruktors freigegeben wird. std::auto_ptr ist nichts anderes als eine Klasse:

class MyAutoPtr {
 void\* ptr;

 MyAutoPtr( void\* \_ptr ) { ptr=\_ptr; }
 ~MyAutoPtr() { delete ptr; }

}

MyAutoPtr x;

Steht x ausserhalb des Scopes einer Funktion oder Klasse, ist also global, so wird der Destruktor nach dem Verlassen von main() aufgerufen.

Ersetze MyAutoPtr durch auto_ptr und verwende einen Typ-Parameter

template
class auto\_ptr {
public:
 auto\_ptr( T\* \_ptr ) { ptr=\_ptr; }
 ~auto\_ptr() { delete ptr; }
 // ... 
}

Gruß Markus