Have I got byte alignment right?

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
JPulham
Posts: 320
Joined: Sat Nov 19, 2005 12:06 pm

Have I got byte alignment right?

Post by JPulham »

I have been playing around with byte alignment in irrArray. I've added to the class.

Code: Select all

T *array_ptr;
unsigned short byte_align;
and added this to the begining of the 'reallocate' method and replaced all 'delete [] data's with 'delete [] array_ptr'

Code: Select all

        if(byte_align)
        {
            new_size += byte_align;
            array_ptr = new char[new_size];
            data = (unsigned long*)(((unsigned long)array_ptr + byte_align) & (0xffffffff - (byte_align - 1)));
        }
        else
        {
            data = array_ptr = new T[new_size];
        }
does this look right or am I setting myself up for a massive bug? :shock:
pushpork
Post Reply