AcArray

AcArray

Anonymous
Not applicable
1,122 Views
6 Replies
Message 1 of 7

AcArray

Anonymous
Not applicable
I hope I don't sound ignorant, but is it safe to store a pointer to an
element in an AcArray? I mean, let's say I have this:
extern MyObject *m_pObj;
extern AcArray > arr;

...
MyObject obj;
int pos = arr.append(obj);
m_pObj = &(arr[pos]); // Is this okay??
...

This is what I'm trying to do: I want to associate an array with a list
box - I could store the *index* of the desired object in the list box, but I
would like to refer to the object from inside the list box class itself (and
therefore will not have access to the array). The array is a data member of
the dialog class . Am I just asking for trouble?
0 Likes
1,123 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Jon,

Another idea...
And if you put a CMap member on your ListBox class (I'm assuming that you
have derived your own ListBox) and fill it with a map between index(integer)
and a pointer (could be a void* or MyObject*).

When user selects the item you just need to get the current selection index,
request its map from the CMap member and use the pointer...

Hope something of this Ball Park helps you... 🙂

Regards,
Fernando.

"Jon Rizzo" wrote in message
news:[email protected]...
> I hope I don't sound ignorant, but is it safe to store a pointer to an
> element in an AcArray? I mean, let's say I have this:
> extern MyObject *m_pObj;
> extern AcArray > arr;
>
> ...
> MyObject obj;
> int pos = arr.append(obj);
> m_pObj = &(arr[pos]); // Is this okay??
> ...
>
> This is what I'm trying to do: I want to associate an array with a list
> box - I could store the *index* of the desired object in the list box, but
I
> would like to refer to the object from inside the list box class itself
(and
> therefore will not have access to the array). The array is a data member
of
> the dialog class . Am I just asking for trouble?
>
>
>
>
0 Likes
Message 3 of 7

Anonymous
Not applicable
Jon,

What about a CMap?
You could map not only index but also the ListBox item contents...

Also, if your ListBox is huge, with CMap the search process will be faster
due the HashTable search mechanism...

I have used CMap on some things and it is very easy to use and fast...

As an other alternative, you may use CArray MFC template class...

Just an idea! 😉
Regards,
Fernando.

"Jon Rizzo" wrote in message
news:[email protected]...
> I hope I don't sound ignorant, but is it safe to store a pointer to an
> element in an AcArray? I mean, let's say I have this:
> extern MyObject *m_pObj;
> extern AcArray > arr;
>
> ...
> MyObject obj;
> int pos = arr.append(obj);
> m_pObj = &(arr[pos]); // Is this okay??
> ...
>
> This is what I'm trying to do: I want to associate an array with a list
> box - I could store the *index* of the desired object in the list box, but
I
> would like to refer to the object from inside the list box class itself
(and
> therefore will not have access to the array). The array is a data member
of
> the dialog class . Am I just asking for trouble?
>
>
>
>
0 Likes
Message 4 of 7

Anonymous
Not applicable
Where to store the pointer is not the issue - the list box already gives me
the ability to store the pointer (performance seems acceptable thus far). I
just need to know if the pointer I am trying to store is safe. (a pointer to
an AcArray element).

Now that I look at it, though, I can probably just make the AcArray a public
member of the CListBox class and avoid the issue all together. There must
be a reason why I didn't do this in the first place, but it escapes me. I'm
trying to modify code that I wrote a long time ago.

I need a vacation. Oh, wait, I just had one...

:-)

Jon

By the same token, would it be safe to store a pointer to an element in a
CArray?
"Fernando Poinho Malard" wrote in message
news:[email protected]...
> Jon,
>
> Another idea...
> And if you put a CMap member on your ListBox class (I'm assuming that you
> have derived your own ListBox) and fill it with a map between
index(integer)
> and a pointer (could be a void* or MyObject*).
>
> When user selects the item you just need to get the current selection
index,
> request its map from the CMap member and use the pointer...
>
> Hope something of this Ball Park helps you... 🙂
>
> Regards,
> Fernando.
>
> "Jon Rizzo" wrote in message
> news:[email protected]...
> > I hope I don't sound ignorant, but is it safe to store a pointer to an
> > element in an AcArray? I mean, let's say I have this:
> > extern MyObject *m_pObj;
> > extern AcArray > arr;
> >
> > ...
> > MyObject obj;
> > int pos = arr.append(obj);
> > m_pObj = &(arr[pos]); // Is this okay??
> > ...
> >
> > This is what I'm trying to do: I want to associate an array with a list
> > box - I could store the *index* of the desired object in the list box,
but
> I
> > would like to refer to the object from inside the list box class itself
> (and
> > therefore will not have access to the array). The array is a data
member
> of
> > the dialog class . Am I just asking for trouble?
> >
> >
> >
> >
>
>
0 Likes
Message 5 of 7

Anonymous
Not applicable
It sounds like your concern was reallocation when the
array needs to grow. Your program structure is the
deciding factor as to if it's safe or not to store
the pointers.

Paul Kohut

"Jon Rizzo" wrote in message
news:[email protected]...
> Where to store the pointer is not the issue - the list box already gives
me
> the ability to store the pointer (performance seems acceptable thus far).
I
> just need to know if the pointer I am trying to store is safe. (a pointer
to
> an AcArray element).
>
> Now that I look at it, though, I can probably just make the AcArray a
public
> member of the CListBox class and avoid the issue all together. There must
> be a reason why I didn't do this in the first place, but it escapes me.
I'm
> trying to modify code that I wrote a long time ago.
>
> I need a vacation. Oh, wait, I just had one...
>
> 🙂
>
> Jon
>
> By the same token, would it be safe to store a pointer to an element in a
> CArray?
> "Fernando Poinho Malard" wrote in message
> news:[email protected]...
> > Jon,
> >
> > Another idea...
> > And if you put a CMap member on your ListBox class (I'm assuming that
you
> > have derived your own ListBox) and fill it with a map between
> index(integer)
> > and a pointer (could be a void* or MyObject*).
> >
> > When user selects the item you just need to get the current selection
> index,
> > request its map from the CMap member and use the pointer...
> >
> > Hope something of this Ball Park helps you... 🙂
> >
> > Regards,
> > Fernando.
> >
> > "Jon Rizzo" wrote in message
> > news:[email protected]...
> > > I hope I don't sound ignorant, but is it safe to store a pointer to an
> > > element in an AcArray? I mean, let's say I have this:
> > > extern MyObject *m_pObj;
> > > extern AcArray > arr;
> > >
> > > ...
> > > MyObject obj;
> > > int pos = arr.append(obj);
> > > m_pObj = &(arr[pos]); // Is this okay??
> > > ...
> > >
> > > This is what I'm trying to do: I want to associate an array with a
list
> > > box - I could store the *index* of the desired object in the list box,
> but
> > I
> > > would like to refer to the object from inside the list box class
itself
> > (and
> > > therefore will not have access to the array). The array is a data
> member
> > of
> > > the dialog class . Am I just asking for trouble?
> > >
> > >
> > >
> > >
> >
> >
>
>
0 Likes
Message 6 of 7

Anonymous
Not applicable
What about MFC

CArray

I'm working with this class instead of AcArray. CArray has more utilities
than AcArray (RemoveAll() i.e)


"Fernando Poinho Malard" wrote in message
news:[email protected]...
> Jon,
>
> Another idea...
> And if you put a CMap member on your ListBox class (I'm assuming that you
> have derived your own ListBox) and fill it with a map between
index(integer)
> and a pointer (could be a void* or MyObject*).
>
> When user selects the item you just need to get the current selection
index,
> request its map from the CMap member and use the pointer...
>
> Hope something of this Ball Park helps you... 🙂
>
> Regards,
> Fernando.
>
> "Jon Rizzo" wrote in message
> news:[email protected]...
> > I hope I don't sound ignorant, but is it safe to store a pointer to an
> > element in an AcArray? I mean, let's say I have this:
> > extern MyObject *m_pObj;
> > extern AcArray > arr;
> >
> > ...
> > MyObject obj;
> > int pos = arr.append(obj);
> > m_pObj = &(arr[pos]); // Is this okay??
> > ...
> >
> > This is what I'm trying to do: I want to associate an array with a list
> > box - I could store the *index* of the desired object in the list box,
but
> I
> > would like to refer to the object from inside the list box class itself
> (and
> > therefore will not have access to the array). The array is a data
member
> of
> > the dialog class . Am I just asking for trouble?
> >
> >
> >
> >
>
>
0 Likes
Message 7 of 7

Anonymous
Not applicable
I am trying to implement AcArray... I need to store an array of objects,
each of which contains an array. Does is my code clean? Below I have my
class definition showing data structures, then the
constructor/desctructor... finally, I have a simple skeleton implementation.
It seems to work OK... but is there anything that needs to be changed to
avoid problems or follow convention??

Thanks,
MS


class CSomeClass
{
public:
CSomeClass();
virtual ~CSomeClass();

struct myStruct
{
AcDbObjectId someObjId;
AcDbObjectIdArray arrObjIds;
};
typedef AcArray ArrMyStruct;
ArrMyStruct arrMyStruct;
};

CSomeClass::CSomeClass()
{
}

CSomeClass::~CSomeClass()
{
while(arrMyStruct.isEmpty())
{
delete ((myStruct*&)arrMyStruct.at(0));
arrMyStruct.removeFirst();
}
}


void someCommand()
{
CSomeClass myClass;

for(int i=0;i {
CSomeClass::myStruct* someInstance=new CSomeClass::myStruct;
myClass.arrMyStruct.append(*someInstance);
}
}
0 Likes