Click here to Skip to main content
15,902,189 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionDisable turning the screen off Pin
aangerma12-Mar-11 22:57
aangerma12-Mar-11 22:57 
AnswerRe: Disable turning the screen off Pin
Hans Dietrich12-Mar-11 23:49
mentorHans Dietrich12-Mar-11 23:49 
AnswerRe: Disable turning the screen off Pin
Eddy Vluggen13-Mar-11 3:30
professionalEddy Vluggen13-Mar-11 3:30 
GeneralRe: Disable turning the screen off Pin
aangerma13-Mar-11 3:48
aangerma13-Mar-11 3:48 
AnswerRe: Disable turning the screen off Pin
Emilio Garavaglia13-Mar-11 10:10
Emilio Garavaglia13-Mar-11 10:10 
GeneralRe: Disable turning the screen off Pin
aangerma13-Mar-11 22:49
aangerma13-Mar-11 22:49 
GeneralRe: Disable turning the screen off Pin
Maximilien14-Mar-11 2:49
Maximilien14-Mar-11 2:49 
Questionit's much slower when using boost::pool_allocator and boost::object_pool Pin
followait12-Mar-11 19:05
followait12-Mar-11 19:05 
the test result on my computer:
//case 1
2153 // not using pool
16 // using pool
//case 2
15 // not using pool
32 // using pool
// case 3
2668 // not using pool
14976 // using pool
Press any key to continue . . .


main.cpp

#include <process.h>
#include "test.h"

int wmain()
{
	test0(10000);
	test1(10000);
	test2(10000);
	test3(10000);
	test4(10000);
	test5(10000);
	system("pause");
	return 0;
}


test.h

#pragma once

void test0(int loops);
void test1(int loops);
void test2(int loops);
void test3(int loops);
void test4(int loops);
void test5(int loops);


test.cpp

#include <iostream>
#include <vector>
#include <boost/pool/pool.hpp>
#include <boost/pool/object_pool.hpp>
#include <boost/pool/pool_alloc.hpp>
#include <windows.h>
#include "test.h"

using namespace std;

class AAA
{
public:
	AAA()
	{
//		cout << "con"  << endl;
	}
	~AAA()
	{
//		cout << "descon" << endl;
	}
public:
	int a;
	char b;
	short int c;
	vector<int> d;
};

void test0(int loops)
{
	char ** p = new char*[loops];

	DWORD tick = GetTickCount();	

	for (int i=0; i<loops; ++i)
		p[i] = new char[32];

	for (int i=0; i<loops; ++i)
		delete []p[i];

	long n = GetTickCount() - tick;

	cout << n << endl;

	delete []p;
};

void test1(int loops)
{
	char ** p = new char*[loops];

	DWORD tick = GetTickCount();

	boost::pool<> memory_pool(32);	

	for (int i=0; i<loops; ++i)
		p[i] = (char*)memory_pool.malloc();

	for (int i=0; i<loops; ++i)
		memory_pool.free(p[i]);

	long n = GetTickCount() - tick;

	cout << n << endl;

	delete []p;
};

void test2(int loops)
{
	DWORD tick = GetTickCount();
	std::vector<int> v;
	for (int i=0; i<loops; ++i)
		v.push_back(i);
	long n = GetTickCount() - tick;
	cout << n << endl;
}

void test3(int loops)
{
	DWORD tick = GetTickCount();
	std::vector<int, boost::pool_allocator<int> > v;
	for (int i=0; i<loops; ++i)
		v.push_back(i);
	long n = GetTickCount() - tick;
	cout << n << endl;
}

void test4(int loops)
{
	AAA ** aa = new AAA*[loops];

	DWORD tick = GetTickCount();	

	for (int i=0; i<loops; ++i)
		aa[i] = new AAA;

	for (int i=0; i<loops; ++i)
		delete aa[i];

	long n = GetTickCount() - tick;
	cout << n << endl;

	delete []aa;
}

void test5(int loops)
{
	AAA ** aa = new AAA*[loops];

	DWORD tick = GetTickCount();

	boost::object_pool<AAA> obj_pool;	

	for (int i=0; i<loops; ++i)
		aa[i] = obj_pool.construct();

	for (int i=0; i<loops; ++i)
		obj_pool.destroy(aa[i]);

	long n = GetTickCount() - tick;
	cout << n << endl;

	delete []aa;
}

AnswerRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Richard MacCutchan12-Mar-11 22:45
mveRichard MacCutchan12-Mar-11 22:45 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
CPallini13-Mar-11 1:44
mveCPallini13-Mar-11 1:44 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Richard MacCutchan13-Mar-11 2:06
mveRichard MacCutchan13-Mar-11 2:06 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
CPallini13-Mar-11 3:02
mveCPallini13-Mar-11 3:02 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
followait13-Mar-11 1:55
followait13-Mar-11 1:55 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Richard MacCutchan13-Mar-11 2:09
mveRichard MacCutchan13-Mar-11 2:09 
AnswerRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Stefan_Lang22-Mar-11 0:20
Stefan_Lang22-Mar-11 0:20 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
followait25-Mar-11 20:13
followait25-Mar-11 20:13 
QuestionCall a extern variable from Application class Pin
Jokcy12-Mar-11 16:35
Jokcy12-Mar-11 16:35 
AnswerRe: Call a extern variable from Application class Pin
David Crow12-Mar-11 17:04
David Crow12-Mar-11 17:04 
GeneralRe: Call a extern variable from Application class Pin
Jokcy12-Mar-11 21:07
Jokcy12-Mar-11 21:07 
GeneralRe: Call a extern variable from Application class Pin
David Crow13-Mar-11 13:09
David Crow13-Mar-11 13:09 
GeneralRe: Call a extern variable from Application class Pin
Jokcy15-Mar-11 21:35
Jokcy15-Mar-11 21:35 
AnswerRe: Call a extern variable from Application class Pin
«_Superman_»12-Mar-11 17:42
professional«_Superman_»12-Mar-11 17:42 
GeneralRe: Call a extern variable from Application class [modified] Pin
Jokcy12-Mar-11 21:16
Jokcy12-Mar-11 21:16 
GeneralRe: Call a extern variable from Application class Pin
«_Superman_»12-Mar-11 22:03
professional«_Superman_»12-Mar-11 22:03 
GeneralRe: Call a extern variable from Application class Pin
Jokcy13-Mar-11 1:34
Jokcy13-Mar-11 1:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.