#include <math.h> #include <stdlib.h> #include <iostream> #include <unistd.h> using namespace std; class Memory { public: int *p; int size; Memory() { p = NULL; } void setSize(int s) { size = s; if (p != NULL) delete[] p; p = NULL; if (size > 0) p = new int[s]; } int getSize() { return size; } void clear() { if (p != NULL) delete[] p; p = NULL; } ~Memory() { if (p != NULL) delete[] p; } }; int main(int argc, char** argv) { struct timespec t = {0, 20000000}; int y = 0; Memory* m = new Memory(); for (int i = -90; i < 630; i++) { y = (int)(1000000.0 * (1.0 + sin(i / 180.0 * 3.14))); m->setSize(y); nanosleep(&t, NULL); } m->clear(); m->setSize(100); return (EXIT_SUCCESS); }
© 2008 - 2015 Солдатов Валерий Фёдорович
Ваши комментарии и замечания.