void abytewriter::write( unsigned char byte )
{
	// safety check for error
	if ( error ) return;
	
	// test if pointer beyond flush threshold
	if ( cbyte >= ( dsize - 2 ) ) {
        if (data) {
            unsigned char * newData = aligned_alloc(dsize *  2);
            memcpy(newData, data, dsize);
            dsize *= 2;
            aligned_dealloc(data);
            data = newData;
        }
		if ( data == NULL ) {
			error = true;
            custom_exit(ExitCode::MALLOCED_NULL);
			return;
		}
	}
	
	// write data
	data[ cbyte++ ] = byte;
}
void abytewriter::write( unsigned char byte )
{
	 
	if ( error ) return;
	
	 
	if ( cbyte >= ( dsize - 2 ) ) {
        if (data) {
            unsigned char * newData = aligned_alloc(dsize *  2);
            memcpy(newData, data, dsize);
            dsize *= 2;
            aligned_dealloc(data);
            data = newData;
        }
		if ( data == NULL ) {
			error = true;
            custom_exit(ExitCode::MALLOCED_NULL);
			return;
		}
	}
	
	 
	data[ cbyte++ ] = byte;
}