This small patch cleans up two things with the allocate aligned memory routine. It cleans up the for loop eliminating the need for the bit operations inside and making it a bit clearer what is happening. It also reduces the memory allocated from twice the rounded up power of two to the rounded up power of two plus the requested size.
Let me know if you like it. David Jacobs --- parrot-0.0.3/memory.c Sat Oct 13 14:43:50 2001 +++ parrot/memory.c Sat Dec 8 18:25:34 2001 @@ -47,19 +47,13 @@ /* Okay, we just brute-force things here. Yeah it's stupid, but it works */ - for (i = 1; i < 0xffffff; i <<= 1) { - if (size > i) { - mask = ~(i*2 - 1); - max_to_alloc = i*4; - } - else { - break; - } - } + for (i = 1; size > i; i <<= 1); + mask = ~(i - 1); + max_to_alloc = i + size; mem = malloc(max_to_alloc); if (((ptrcast_t)mem & mask) < (ptrcast_t)mem) { - mem = (void *)(((ptrcast_t)mem & mask) + ~mask + 1); + mem = (void *)(((ptrcast_t)mem & mask) + i); } return mem; }