Click here to Skip to main content
12,621,430 members (30,115 online)
Click here to Skip to main content

Tagged as

Stats

8.3K views
82 downloads
3 bookmarked
Posted

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

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 28 May 2012
Article Copyright 2012 by goecerfun
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid