Class BuddyAllocator

Class Documentation

class BuddyAllocator

the buddy system on 2^m words

Public Functions

explicit BuddyAllocator(int m)

a memory of 2^m words, all free

Pre:

0 <= m <= 40, and 2^m fits in a long (m <= 30 where long has 32 bits)

long allocate(long n)

a block of at least n words, a power of 2, or -1

Pre:

n >= 1

void free(long a)

frees the block at a

Pre:

a was given by allocate() and is in use

long freeWords(void) const

the words in free blocks

long blockSize(long a) const

the size of the block in use at a

Pre:

a is in use