Re: VS 2008 "Containers"
On Nov 1, 2:53 am, "JCO" <some...@somewhere.com> wrote:
Thanks...
But I where I'm not understanding is the GetSize() vs GetCount(). Actu=
ally
recList.GetCount() makes sense as this is the number of records (in my ca=
se
number of structures). However, recListGetSize() gives me the same num=
ber
as GetCount(). It's not a big issues for what I'm doing since I'm not
making use of GetSize(). I just noticed it while in debug mode and was
curious.
Thanks again
"Joseph M. Newcomer" <newco...@flounder.com> wrote in messagenews:443nc69=
pcjtpvt1i4cg93iti7urj7g4e9o@4ax.com...
See below...
On Fri, 29 Oct 2010 18:05:30 -0500, "JCO" <some...@somewhere.com> wrote=
:
struct Record
{
CString strName;
int iAge;
double fWheight;
.......
........
};
CList<Record,Record&> recList(10);
I've read all the comments, but as suggested, I'm using the CList.
One question that I can't seem to figure out. I see where you can
instantiate it with a certain number of blocks (say 10 representing 10 =
of
my
structures). It appears that if I go over 10, it will automatically =
grow.
However, while looking at the debugger, I don't see that the size is
clearly
increased. I do see the count growing to 20 with no issues.
****
It is the nature of a list that you would NOT instantiate it with a
preallocated number of
blocks; in fact, all lists are instantiated with 0 blocks and blocks ar=
e
added as needed.
****
I'm guessing that it grows by the initial number I gave, therefore, gro=
ws
by
10 each time I exceed the Max total count. Is this a true assumption=
?
****
There would be no reason to grow it by a number of elements that do not
need to exist.
What is going on here is how memory is allocated, not how list elements
are allocated.
Instead of calling 'new' to create a new element of the list, the eleme=
nt
is allocated out
of the block of memory that is currently being held. That is, a
sub-allocator is being
used. If all of the storage is used up, another block of N cells is
allocated, and then
sub-allocated. The goal here is to prevent the kind of fragmentation=
that
results in
massive performance hits that pure 'new' would give. But it is a klu=
dge
that really
doesn't solve the fundamental problem (such as how long it takes to sea=
rch
to find where
to put something)
Go read the code in afxtempl.h for the NewNode function.
****
I know... never assume! That's why I'm asking.
****
In this case, it is not an assumption; it is a stated property of the
class.
joe
****
Thanks
"Joseph M. Newcomer" <newco...@flounder.com> wrote in message
news:benjc6pebd2uaqp9fqumonrie5fv4j3irm@4ax.com...
CList, std::list
joe
On Thu, 28 Oct 2010 15:23:51 -0500, "JCO" <some...@somewhere.com> wro=
te:
Using VS2008, C++, MFC
Writing some code that requires me to load "Records" into memory. =
Each
record contains 3-CString's, TCHAR, int, 2-Doubles. Therefore, I'm
creating
a Link List Class as part of the project. The Link List is almost =
done
and
it works fine, however, if I wanted to use a C++ container of some ty=
pe
to
accomplish the same thing, what can use?
Thanks
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
Both the CList::GetSize() and CList::GetCount() returns the number of
elements in the list.
http://msdn.microsoft.com/en-us/library/sd2bz44c(VS.80).aspx
I don't know why MFC people provided two method for the same
functionality. The source of both function is exactly same.
template<class TYPE, class ARG_TYPE>
AFX_INLINE INT_PTR CList<TYPE, ARG_TYPE>::GetCount() const
{ return m_nCount; }
template<class TYPE, class ARG_TYPE>
AFX_INLINE INT_PTR CList<TYPE, ARG_TYPE>::GetSize() const
{ return m_nCount; }