Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tagged as

Ideas from a smart pointer. Support data-alignment (part 1)

, 28 May 2012 CPOL
embedded ref-counted resource management
// testsmart.cpp : �������̨Ӧ�ó������ڵ㡣
//

#include "stdafx.h"

struct A
{
	A()
	{
		printf("A()\n");
	}

	virtual ~A()
	{
		printf("~A()\n");
	}
};

struct B: A
{
	B()
	{
		printf("B()\n");
	}

	virtual ~B()
	{
		printf("~B()\n");
	}
};

Single<A*>::Ref g_pA;

int _tmain(int argc, _TCHAR* argv[])
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF); //auto detect memory leak

	Single<A*>::Ref pB = SingleAlloc<B>(); //ref new B
	g_pA = pB; //auto InterlockedIncrement(ref-counter)

	Array<A*>::Ref pAs = ArrayAlloc<A>(4); //ref new A[4]

	SingleAligned<A*>::Ref pA_aligned = SingleAllocAligned<A>(16); //16 bytes aligned
	
	ArrayAligned<A*>::Ref pAs_aligned = ArrayAllocAligned<B>(5, 16); //16 bytes aligned array(5 elements)

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

goecerfun

China China
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.141022.1 | Last Updated 28 May 2012
Article Copyright 2012 by goecerfun
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid