|
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "Scope.h"
TScope global; // this one is threadsafe and deallocates all associated objects on program exit no matter
// what exception or error in program happens
struct A : Scope::Obj{ // to support autocleanup functionality just derive from Scope::Obj
A(){ printf("\n A %x",this); } // so Scope knows which destructor to call
~A(){ printf("\n ~A %x",this); }
};
void Test() {
Scope local; // all objects associated with scope will be deallocated by leaving procedure
A* array[3]={0};
for(int i=0;i<3;i++) {
array[i]=new(local) A();
}
char* text=strdup(global,"this will get deallocated on program exit"); //associate with global scope
A* a=new(global) A(); // this will get destructor called on progam exit
}
void main() {
Test();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.