コード例 #1
0
ファイル: main.cpp プロジェクト: astromaker/sandbox
int	main()
{
#if		defined(CRT_LFH)

	::wprintf(L"crt lfh\n");

	set_lfh();

#elif	defined(TBBMALLOC)

	::wprintf(L"tbbmalloc\n");

#elif	defined(TCMALLOC)

	::wprintf(L"tcmalloc\n");

#elif	defined(JEMALLOC)

	::wprintf(L"jemalloc\n");

	set_jemalloc();

#elif	defined(MS_CONCURRENCY)

	::wprintf(L"ms concurrency\n");

#elif	defined(MY_ALLOCATOR)

	::wprintf(L"my allocator\n");

	if (allocator.create(true, 0) == false)
	{
		::wprintf(L"allocator.create() failed.\n");
		return 0;
	}

#endif

	// for crt tbb tcmalloc
	char* dummy = new char[10];
	SecureZeroMemory(dummy, 10);

	::wprintf(L"start memory info\n");
	print_memory_info();

	HANDLE thread_handle[thread_count] = { nullptr, };

	ULONGLONG start = ::GetTickCount64();
	for (std::size_t i = 0; i < thread_count; ++i)
	{
		unsigned int id = 0;
		thread_handle[i] = reinterpret_cast< HANDLE >(::_beginthreadex(nullptr, 0, memory_alloc_test_thread_func, nullptr, 0, &id));
		if (thread_handle[i] == nullptr)
		{
			::wprintf(L"%llu: _beginthreadex failed.\n", i);
		}
	}

	::WaitForMultipleObjects(thread_count, thread_handle, TRUE, INFINITE);

	ULONGLONG run_time = ::GetTickCount64() - start;
	::wprintf(L"run time: %llu\n", run_time);

	for (std::size_t i = 0; i < thread_count; ++i)
	{
		if (thread_handle[i] != nullptr)
		{
			::CloseHandle(thread_handle[i]);
			thread_handle[i] = nullptr;
		}
	}

	delete[] dummy;
	dummy = nullptr;

	::wprintf(L"end memory info\n");
	print_memory_info();

#if defined(MY_ALLOCATOR)
	print_allocator_stat(allocator.get_statistics());
	allocator.destroy();
#elif defined(JEMALLOC)
	{
		//je_malloc_stats_print(nullptr, nullptr, nullptr);

		size_t sz = sizeof(jemalloc_post_allocated);
		je_mallctl("stats.active", &jemalloc_post_allocated, &sz, nullptr, 0);

		size_t leaked = jemalloc_post_allocated - jemalloc_pre_allocated;
		::wprintf(L"\nDone. Leaked: %zd bytes\n", leaked);
		bool failed = leaked > 65536; // in case C++ runtime allocated something (e.g. iostream locale or facet)
		::wprintf(L"\nTest %s!\n", (failed ? L"FAILED" : L"successful"));
	}
#endif

	return 0;
}
コード例 #2
0
int	main()
{
#if		defined( CRT_LFH )

	::wprintf(L"crt lfh\n");

	set_lfh();

#elif	defined( TBBMALLOC )

	::wprintf(L"tbbmalloc\n");

#elif	defined( TCMALLOC )

	::wprintf(L"tcmalloc\n");

#elif	defined( MS_CONCURRENCY )

	::wprintf(L"ms concurrency\n");

#elif	defined( LOOKASIDE_HEAP )

	::wprintf(L"lookaside heap\n");

	if (allocator.create(true) == false)
	{
		::wprintf(L"allocator.create() failed.\n");
		return 0;
	}

#endif

	HANDLE thread_handle[thread_count] = { nullptr, };

	DWORD start = ::GetTickCount();
	for (int i = 0; i < thread_count; ++i)
	{
		unsigned int id = 0;
		thread_handle[i] = reinterpret_cast< HANDLE >(::_beginthreadex(nullptr, 0, memory_alloc_test_thread_func, nullptr, 0, &id));
		if (thread_handle[i] == nullptr)
		{
			wprintf(L"%d: _beginthreadex failed.\n", i);
		}
	}

	::WaitForMultipleObjects(thread_count, thread_handle, TRUE, INFINITE);

	DWORD run_time = ::GetTickCount() - start;
	::wprintf(L"run time: %d\n", run_time);

	for (int i = 0; i < thread_count; ++i)
	{
		if (thread_handle[i] != nullptr)
		{
			::CloseHandle(thread_handle[i]);
			thread_handle[i] = nullptr;
		}
	}

#ifdef	LOOKASIDE_HEAP
	print_allocator_stat(&allocator);
	allocator.destroy();
#endif

	return 0;
}