[comp.sys.mac.programmer] On writing an LDEF to draw icons: store icon data or handle?

UN020070@WVNVAXA.WVNET.EDU (06/02/91)

Subject:  On writing an LDEF to draw icons: store icon data or handle?
Newsgroups: comp.sys.mac.programmer
Reply-To: un020070@vaxa.wvnet.edu

I'm writing a list definition (LDEF) to draw icons from the list manager.
I can think of two ways to store the data:

1.  Store the actual data (128 bytes, I think) of the icon as the cell
    data.
2.  Store a *handle* to the icon in the cell data; this will make the
    cell data only a longword long.  The icon itself will be somewhere
    else in memory.

The list I will be using this for will be very similar to the one in
Hypercard for selecting button icons, except that the user will be
able to add new icons and to edit them (although the list will be
dismissed before the editing occurs, so that's not a major consideration.)

Does anyone have any experience in doing this?  What are the pros and
cons of the two strategies?

Please respond by email since I have in fact lost my ability to
post and read news and must now smuggle this posting in through
a daemon-posessed email address.  (This is the first time I have
tried doing this; if nobody sees this, please let me know :-)

--Kurisuto
un020070@vaxa.wvnet.edu

ari@eleazar.dartmouth.edu (Ari Halberstadt) (06/03/91)

In article <01G6IKL90CBQ8WWD4Y@WVNVMS.WVNET.EDU> you write:
>Subject:  On writing an LDEF to draw icons: store icon data or handle?
>Newsgroups: comp.sys.mac.programmer
>Reply-To: un020070@vaxa.wvnet.edu
>
>I'm writing a list definition (LDEF) to draw icons from the list manager.
>I can think of two ways to store the data:
>
>1.  Store the actual data (128 bytes, I think) of the icon as the cell
>    data.

This is fairly simple. If your icon is 128 bytes, then you can have a
maximum of 32768 (or is it 32767) divided by the size of an icon,
which gives us 256 (no, 255) icons in the list. This is a very compact
way to store them: no wasted space, but 255 is a very small number.
And if you're also storing an icon mask, then each icon is twice as
big, giving you even less icons in the list.


>2.  Store a *handle* to the icon in the cell data; this will make the
>    cell data only a longword long.  The icon itself will be somewhere
>    else in memory.
>

This way you can have 32767/4 = 8191 icons. But you'll waste more
space: 8 bytes for each handle header, plus 4 bytes for each master
pointer, or a maximum "wasted" space of 12 * 8191 = 98292. This is a lot.

A better solution is to store the icon's ID, or only 2 bytes per icon,
giving you a maximum of 16383 icons with no wasted space.
When you need the icon, simply call GetIcon. If the icon has been purged,
then it will be read in, if it's not purged it will be returned immediately.