僕はこうやる。
max_size = 0;
for (bit = 0x80000000; bit > 0; bit >>= 1) {
mem = malloc(max_size | bit);
if (mem != NULL) {
free(mem);
max_size |= bit;
}
}