//
// Microsoft .NET CLR
//

#include "../comnhdr.h"

#define BITMAPSIZE			400 * 1024

void TouchBuffer(void * _buffer, size_t size)
{
	UNREFERENCED_PARAMETER(size);
	memset(_buffer, 0, 10);
}

using namespace System;

ref class CBitmap {
public:
	array<Byte> ^	m_pBuffer;
	CBitmap ^		m_pSelf;
	CBitmap() {
		m_pBuffer = gcnew array<Byte>(BITMAPSIZE);
	}
	void LoadAndDisp() {
		// Invoke native function to process data
		pin_ptr<Byte> p1;	// limit: cannot be a global or static variable, nor a member variable.
		p1 =  &m_pBuffer[ 0 ];
		TouchBuffer(p1, BITMAPSIZE);
	}
};

void TestDispBitmap() {
	CBitmap ^ pBitmap = gcnew CBitmap;
	pBitmap->m_pSelf = pBitmap;
	pBitmap->LoadAndDisp();
}

int main () {
	for (int j = 0; j < 20; j++) {
		BenchTicks_t bt = BenchTicksGetCurrent();
		for (int i = 0; i < 1000; i++) {
			TestDispBitmap();
		}
		bt = BenchTicksGetCurrent() - bt;
		printf("Completed in %s\n", BenchTicksToString(bt, false));
		Sleep(10);
	}
	return 0;
}

