CHeapPtr 클래스

힙 포인터를 관리하기 위한 스마트 포인터 클래스입니다.

Important

이 클래스와 해당 멤버는 Windows 런타임에서 실행되는 애플리케이션에서 사용할 수 없습니다.

구문

template<typename T, class Allocator=CCRTAllocator>
class CHeapPtr : public CHeapPtrBase<T, Allocator>

매개 변수

T
힙에 저장할 개체 형식입니다.

할당자
사용할 메모리 할당 클래스입니다.

멤버

공용 생성자

속성 설명
CHeapPtr::CHeapPtr 생성자입니다.

공용 메서드

이름 설명
CHeapPtr::Allocate 개체를 저장할 힙에 메모리를 할당하려면 이 메서드를 호출합니다.
CHeapPtr::Reallocate 힙에서 메모리를 다시 할당하려면 이 메서드를 호출합니다.

Public 연산자

이름 설명
CHeapPtr::operator = 할당 연산자입니다.

설명

CHeapPtr는 CHeapPtrBase에서 파생되며 기본적으로 CRT 루틴(CCRTAllocator)을 사용하여 메모리를 할당하고 해제합니다. CHeapPtrList 클래스를 사용하여 힙 포인터 목록을 생성할 수 있습니다. COM 메모리 할당 루틴을 사용하는 CComHeapPtr참조하세요.

상속 계층 구조

CHeapPtrBase

CHeapPtr

요구 사항

헤더: atlcore.h

CHeapPtr::Allocate

개체를 저장할 힙에 메모리를 할당하려면 이 메서드를 호출합니다.

bool Allocate(size_t nElements = 1) throw();

매개 변수

nElements
할당할 메모리 양을 계산하는 데 사용되는 요소 수입니다. 기본값은 1입니다.

Return Value

메모리가 성공적으로 할당되면 true를 반환하고 실패하면 false를 반환합니다.

설명

할당자 루틴은 생성자에 정의된 형식의 nElement 개체를 저장할 충분한 메모리를 힙에 예약하는 데 사용됩니다.

예시

// Create a new CHeapPtr object
CHeapPtr <int> myHP;
// Allocate space for 10 integers on the heap
myHP.Allocate(10);

CHeapPtr::CHeapPtr

생성자입니다.

CHeapPtr() throw();
explicit CHeapPtr(T* p) throw();
CHeapPtr(CHeapPtr<T, Allocator>& p) throw();

매개 변수

p
기존 힙 포인터 또는 CHeapPtr.

설명

힙 포인터는 필요에 따라 기존 포인터 또는 CHeapPtr 개체를 사용하여 만들 수 있습니다. 이 경우 새 CHeapPtr 개체는 새 포인터 및 리소스를 관리하는 책임을 맡습니다.

예시

// Create a new CHeapPtr object
CHeapPtr <int> myHP;
// Create a new CHeapPtr from the first
CHeapPtr <int> myHP2(myHP);   

CHeapPtr::operator =

대입 연산자입니다.

CHeapPtr<T, Allocator>& operator=(
    CHeapPtr<T, Allocator>& p) throw();

매개 변수

p
기존 CHeapPtr 개체입니다.

Return Value

업데이트 CHeapPtr된 에 대한 참조를 반환합니다.

예시

// Create a new CHeapPtr object
CHeapPtr <int> myHP;
// Allocate space for 10 integers on the heap
myHP.Allocate(10);
// Create a second heap pointer
// and assign it to the first pointer.
CHeapPtr <int> myHP2;
myHP2 = myHP;   

CHeapPtr::Reallocate

힙에서 메모리를 다시 할당하려면 이 메서드를 호출합니다.

bool Reallocate(size_t nElements) throw();

매개 변수

nElements
할당할 메모리 양을 계산하는 데 사용되는 새 요소 수입니다.

Return Value

메모리가 성공적으로 할당되면 true를 반환하고 실패하면 false를 반환합니다.

예시

// Create a new CHeapPtr object
CHeapPtr <int> myHP;
// Allocate space for 10 integers on the heap
myHP.Allocate(10);
// Resize the allocated memory for 20 integers
myHP.Reallocate(20);   

참고 항목

CHeapPtrBase 클래스
CCRTAllocator 클래스
클래스 개요