Smartpointer question?

Smartpointer question?

D_D_K
Advocate Advocate
986 Views
3 Replies
Message 1 of 4

Smartpointer question?

D_D_K
Advocate
Advocate

Hi,

can I combine AcDbObjectPointer and AcDbVoidPtrArray ?

The problem I'm having is the pointer doesn't seem to be valid after the end of the function.

How do I use smartpointer in this case? because I want to avoid delete pointer.

 

bool Dosomething(AcDbCircle* c,...); //

void myfunc(AcDbVoidPtrArray &vrr){
AcDbObjectPointer<CIR> cptr; cptr.create();
CIR* cir = cptr.object();
if (Dosomething(cir,...))
   vrr.append(cir);
}

 

 Thanks for the explanation.

0 Likes
Accepted solutions (1)
987 Views
3 Replies
Replies (3)
Message 2 of 4

Alexander.Rivilis
Mentor
Mentor
Accepted solution

@D_D_K wrote:

Hi,

can I combine AcDbObjectPointer and AcDbVoidPtrArray ?

The problem I'm having is the pointer doesn't seem to be valid after the end of the function.

How do I use smartpointer in this case? because I want to avoid delete pointer.

 

bool Dosomething(AcDbCircle* c,...); //

void myfunc(AcDbVoidPtrArray &vrr){
AcDbObjectPointer<CIR> cptr; cptr.create();
CIR* cir = cptr.object();
if (Dosomething(cir,...))
   vrr.append(cir);
}

 

 Thanks for the explanation.


 

 

bool Dosomething(AcDbCircle* c,...); //

void myfunc(AcDbVoidPtrArray &vrr){
AcDbObjectPointer<CIR> cptr; cptr.create();
CIR* cir = cptr.object();
if (Dosomething(cir,...)) {
   CIR *cir1 = NULL;
   cir.release(cir1); // <- prevent from destructor
   vrr.append(cir1);
}

 

Other way is not using smart pointer in this case.

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 3 of 4

D_D_K
Advocate
Advocate

Thank sir! 

I got it. maybe I'll save it for other cases. 🗯

0 Likes
Message 4 of 4

trithuongle
Advocate
Advocate

Good morning , I have a question .

With the above sample , when AcDbObjectPtrArray vrr go out of its scope in main function , do we need to delete or close its member 's pointers ?

I also have the similar code in which i'm using AcDbObjectPtrArray.

Thanks in advance !

 

AcDbVoidPtrArray lineObjs;
    AcDbObjectPointer<AcDbLine> tempLine;
    AcDbObjectId oId;
    ads_point startPnt, nextPnt;

    acedGetPoint(NULL, _T("\nStart point : "), startPnt);

    for (int i = 0; i < 10; i++)
    {
        acedGetPoint(startPnt, _T("\nNext point : "), nextPnt);
       
        tempLine.create();
        tempLine->setStartPoint(asPnt3d(startPnt));
        tempLine->setEndPoint(asPnt3d(nextPnt));
        tempLine->setLayer(_T("1"));

        addToCurSpace(oId, tempLine);

        AcDbLine* pTemp = nullptr;
        tempLine.release(pTemp);

        lineObjs.append(pTemp);

        acdbPointSet(nextPnt, startPnt);
    } 

    acutPrintf(_T("\nNumber of lines : %d"), lineObjs.length());
    //<- do we need to delete or close AcDbVoidPtrArray 's member pointer here ?
    //If not does it cause memory leak ?

 

 

 

0 Likes