00001
00002
00003
00004
00005
00006
00007
00008 #include <utility/ostream.h>
00009 #include <utility/string.h>
00010 #include <utility/malloc.h>
00011
00012 __USING_SYS;
00013
00014 int main()
00015 {
00016 OStream cout;
00017
00018 cout << "Memory allocation test\n";
00019 char * cp = new char('A');
00020 cout << "new char('A')\t\t=> {p=" << (void *)cp << ",v=" << *cp << "}\n";
00021 int * ip = new int(1);
00022 cout << "new int(1)\t\t=> {p=" << (void *)ip << ",v=" << *ip << "}\n";
00023 long int * lp = new long int(1);
00024 cout << "new long int(1)\t\t=> {p=" << (void *)lp << ",v=" << *lp << "}\n";
00025 char * sp = new char[1024];
00026 strcpy(sp, "string");
00027 cout << "new char[1024]\t\t=> {p=" << (void *)sp << ",v=" << sp << "}\n";
00028
00029 cout << "deleting everything!\n";
00030 delete cp;
00031 delete ip;
00032 delete lp;
00033 delete sp;
00034
00035 cout << "and doing it all again!\n";
00036 cp = new char('A');
00037 cout << "new char('A')\t\t=> {p=" << (void *)cp << ",v=" << *cp << "}\n";
00038 ip = new int(1);
00039 cout << "new int(1)\t\t=> {p=" << (void *)ip << ",v=" << *ip << "}\n";
00040 lp = new long int(1);
00041 cout << "new long int(1)\t\t=> {p=" << (void *)lp << ",v=" << *lp << "}\n";
00042 sp = new char[1024];
00043 strcpy(sp, "string");
00044 cout << "new char[1024]\t\t=> {p=" << (void *)sp << ",v=" << sp << "}\n";
00045
00046
00047 return 0;
00048 }