Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CImageList::Create()

97 views
Skip to first unread message

slash

unread,
Feb 14, 2006, 1:46:00 AM2/14/06
to
Dear All,

I have read the msdn about the CImageList::Create(), but I don't really
get it about the `nGrow' parameter, could anyone explain it to me ?!

its prototype is:
BOOL Create( int cx, int cy, UINT nFlags, int nInitial, int nGrow );

nInitial
Number of images that the image list initially contains.

nGrow
Number of images by which the image list can grow when the system needs
to resize the list to make room for new images. This parameter
represents the number of new images the resized image list can contain.

Say if we want to create a CImageList object with 6 16x15 images:

m_imageList.Create(16, 15, ILC_COLOR, ?, ?);

What should we give in the last 2 parameters ?!
Thanks.


Slash

David Webber

unread,
Feb 14, 2006, 3:42:45 AM2/14/06
to

"slash" <sl...@ms32.url.com.tw> wrote in message
news:1139899560.3...@o13g2000cwo.googlegroups.com...

> I have read the msdn about the CImageList::Create(), but I don't really
> get it about the `nGrow' parameter, could anyone explain it to me ?!

As I understand it (someone correct me if I'm wrong in this case) that
dynamic array objects often have two "size" parameters:

size1 the number of objects which are curently held
size2 the number of objects for which memory is currently allocated.

with size2 greater than or equal to size1.

As you fill it up the spare locations are occupied and size1 grows towards
size2.

When size1 is equal to size2, and you add another element, extra memory is
allocated for "nGrow" objects, leaving nGrow-1 free spaces. The purpose is
to make it possible to have rather few reallocation operations if you know
you're going to add a lot of things to the array, but not to use up lots of
memory if you know you're going to have rather few.

Dave

--
David Webber
Author MOZART the music processor for Windows -
http://www.mozart.co.uk
For discussion/support see
http://www.mozart.co.uk/mzusers/mailinglist.htm

Tom Serface

unread,
Feb 14, 2006, 10:40:19 AM2/14/06
to
I think you'll find that most of the time you'll know the number of images
you're going to put into an image list because you'll be using it for a tree
or list control where you are using a bitmap to split up into images.
However, if you are using it dynamically where you are adding images "as you
go along" you will want to set this to some reasonable amount so that memory
doesn't get fragmented by allocating lots of little chunks. For example, if
you are going to continually add bitmaps each having 5 images you could set
the nGrow setting to 5 since you would know the size of each block.
However, I typically put the original number of images in the first number
(the number of images in my bitmap for the control where I'm using the list)
and 1 for the second parameter since I seldom add additional images.

Tom

"slash" <sl...@ms32.url.com.tw> wrote in message
news:1139899560.3...@o13g2000cwo.googlegroups.com...

slash

unread,
Feb 16, 2006, 2:04:43 AM2/16/06
to
Dear David Webber, Tom Serface,

Thanks for the wonderful explanation !


Slash

0 new messages