Пример #1
0
int main(int argc, char *argv[]) {
    int epochs = (argc > 1) ? atoi(argv[1]) : 0;


    int i;
    void *lowbreak, *highbreak;
    memblock_t block[epochs];
    srand(SEED);

    /* Initialize structure */
    for (i = 0; i < epochs; ++i) {
        block[i].ptr = NULL;
        block[i].size = 0;
    }

    lowbreak = getbreak();


    for (i = 0; i < epochs; ++i) {
        /* Malloc 2, 4, ... up to 1024 and reset */
        block[i].size = (2 << (i % 10)); //Up to 1022
        block[i].ptr = malloc(block[i].size);

        if (block[i].ptr == NULL) {
            perror("Error: Insufficient memory when mallocing.");
            exit(1);
        }    
    }


    for (i = 0; i < epochs; ++i) {
        free(block[i].ptr);
    }

    highbreak = getbreak();

    fprintf(stderr, "Memory usage: %u b\n", highbreak-lowbreak);

    return 0;
}
Пример #2
0
int main(int argc, char *argv[]) {
    int epochs = (argc > 1) ? atoi(argv[1]) : 0;


    int i;
    void *lowbreak, *highbreak;
    memblock_t block[epochs];
    srand(5);

    /* Initialize structure */
    for (i = 0; i < epochs; ++i) {
        block[i].ptr = NULL;
    }

    lowbreak = getbreak();


    for (i = 0; i < epochs; ++i) {
        /* Malloc with constant size MAXSIZE */
        block[i].size = MAX_SIZE;
        block[i].ptr = malloc(block[i].size);

        if (block[i].ptr == NULL) {
            perror("Error: Insufficient memory when mallocing.");
            exit(1);
        }    
    }


    for (i = 0; i < epochs; ++i) {
        free(block[i].ptr);
    }

    highbreak = getbreak();

    fprintf(stderr, "Memory usage: %u b\n", highbreak-lowbreak);

    return 0;
}
Пример #3
0
int cmd_break(char *param)
{
	switch(onoffStr(param)) {
  	default:
		error_on_off();
		return 1;
	case OO_Null:	case OO_Empty:
		displayString(TEXT_MSG_BREAK_STATE, getbreak() ? D_ON : D_OFF);
		break;
  	case OO_Off:	setbreak(0);	break;
  	case OO_On:		setbreak(1);	break;
	}

	return 0;
}