program sncMalloc
long current;
int size;
long kbytes;
assign kbytes to "mem_in_kbytes";
monitor kbytes;

%% #include 
%% char *p;
%% int i;

ss ss1 {
    state init {
	when (delay(1)) {
	    printf("sncMalloc: Startup delay over\n");
	    current = 0;
	} state wait_req
    }
    state wait_req {
	when (kbytes > current) {
	    size = (kbytes - current) * 1000;
%{
	    p = (char *) mallocMustSucceed(size, "sncMalloc: malloc failed");
	    for (i = 0; i < size; i++) {
	        p[i] = (char) i;
	    }
}%
	    current = kbytes;
	    printf("sncMalloc: allocated %d bytes\n", size);
	} state wait_req
    }
}