buddy memory allocation - main function
<p>Im new to C++, i found this code of buddy system memory allocation but with no main function, all member function are correct, i want you guys to help me with the main function, i wanna allocate some memory and then show the state of the memory before and after allocation, and then deallocate the memory to verify that buddies are merging, and show the list of free blocks</p>

<p>--BuddyPool.h--</p>

<pre><code>#ifndef  BUDDYPOOL_INC
#define  BUDDYPOOL_INC

class BuddyPool{
public:
    enum Status { free, reserved };
    struct Header
    {
        Status status: 1;
        //unsigned int k : bitsizeof(unsigned int) - 1U;
        unsigned int k : 31;
    };
    struct Block : public Header
    {
        //enum { size = 16 };

        enum { size = 64 };
        struct Links
        {
            Block *next;
            Block *prev;
        };
        union
        {
            Links link;
            char userPart [size - sizeof(Header)];
        };
    };

private:
    unsigned int m;
    unsigned int numberOfBlocks;
    Block *pool;
    Block *sentinel;

    static void Unlink(Block &amp;);
    static void InsertAfter(Block &amp;, Block &amp;);
    Block &amp;Buddy(Block &amp;) const;

public:
    BuddyPool(size_t);
    ~BuddyPool();

    void *Acquire(size_t);
    void Release(void *);
};

#endif   /* ----- #ifndef BUDDYPOOL_INC  ----- */
</code></pre>

<p>--BuddyPool.cpp--</p>

<pre><code>#include &lt;WinDef.h&gt;
#include "BuddyPool.h"

unsigned int Log2Ceil(unsigned int val){
    unsigned int L;
    for (L = 0; (1ul&lt;&lt;L) &lt; val; L++);
    return L;
}

BuddyPool::BuddyPool(size_t bytes) 
    : m(Log2Ceil(bytes))
    , numberOfBlocks( (1 &lt;&lt; m) / sizeof(Block))
    , pool (new Block[numberOfBlocks + m +1])
    , sentinel(pool + numberOfBlocks)
{
    for (unsigned int i = 0; i &lt;= m; ++i) {
        sentinel[i].link.next = &amp;sentinel[i];
        sentinel[i].link.prev = &amp;sentinel[i];
    }

    Block &amp;head = pool[0];
    head.status = free;
    head.k = m;
    InsertAfter(sentinel[m], head);
}

BuddyPool::~BuddyPool(){
    delete [] pool;
}

void *BuddyPool::Acquire(size_t bytes){
    unsigned int kPrime = Log2Ceil(bytes + sizeof(Header));

    unsigned int i = kPrime;
    while (i &lt;= m &amp;&amp; sentinel[i].link.next == &amp;sentinel[i]) {
        ++i;
    }
    if (i &gt; m) {
        return NULL;    // throw bad_alloc("out of memory");
    }

    Block &amp;block = *sentinel[i].link.next;
    Unlink(block);
    while (block.k &gt; kPrime) {
        block.k -= 1;
        Block &amp;buddy = Buddy(block);
        buddy.status = free;
        buddy.k = block.k;
        InsertAfter(sentinel[buddy.k], buddy);
    }
    block.status = reserved;
    return block.userPart;
}

void BuddyPool::Release(void *arg){
    Block &amp;block = *reinterpret_cast&lt;Block *&gt;(
                                              reinterpret_cast&lt;Header *&gt;(arg) - 1U);

    if (&amp;block &lt; pool || &amp;block &gt;= pool + numberOfBlocks) {
        return; // throw invalid_argument("invalid pointer");
    }

    block.status = free;
    Block *ptr;
    for (ptr = &amp;block; ptr-&gt;k &lt; m; ptr-&gt;k += 1) {
        Block &amp;buddy = Buddy(*ptr);
        if (buddy.status == reserved || buddy.k != ptr-&gt;k) {
            break;
        }
        Unlink(buddy);
        if (&amp;buddy &lt; ptr) {
            ptr = &amp;buddy;
        }
    }

    InsertAfter(sentinel[ptr-&gt;k], *ptr);
}

BuddyPool::Block &amp;BuddyPool::Buddy(Block &amp;block) const{
    unsigned int addr = reinterpret_cast&lt;unsigned int&gt;(&amp;block) + (1 &lt;&lt; block.k);
    return *(reinterpret_cast&lt;Block *&gt;(addr));
}

void BuddyPool::Unlink(Block &amp;block){
    if (block.link.next) {
        block.link.next-&gt;link.prev = block.link.prev;
    }
    if (block.link.prev) {
        block.link.prev-&gt;link.next = block.link.next;
    }
    block.link.next = block.link.prev = &amp;block;
}

void BuddyPool::InsertAfter(Block &amp;src, Block &amp;block){
    block.link.next = src.link.next;
    block.link.prev = &amp;src;

    if (src.link.next) {
        src.link.next-&gt;link.prev = &amp;block;
    }
    src.link.next = &amp;block; 
}
</code></pre>
