#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char** argv) {
int max = 2048; // сколько МБ занимать
int wait = 60 ; // сколько времени ждать
int mb = 0 ;
char* buffer;
while((buffer=malloc(1024*1024)) != NULL && mb != max) {
memset(buffer, 0, 1024*1024);
mb++;
}
printf("Allocated %d MB\n", mb);
while ( wait > 0 ) {
printf("\rHold memory for %d seconds", wait);
fflush( stdout );
sleep(1);
wait-- ;
}
printf("\nMemory is freed\n");
return 0;
}
template<template<typename U, typename Allocator> class Container, typename T, size_t n>
Container<T, allocator<T> > ContainerMake(const T(&array)[n])
{
return Container<T, allocator<T> >(array, array + n);
}
const int vals1[] = {0, 1, 2, 3, 4};
vector<int> vct1 = ContainerMake<vector>(vals1);