🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.windows.ms.programmer
Article #2024

Re: How to best represent a list in Windows?

#2024
From: Tony Gosling
Date: Wed, 10 Apr 1991 06:09
58 lines
2494 bytes
In article <1991Apr5.205519.29757@sunee.waterloo.edu>, gpsteffl@sunee.waterloo.edu (Glenn Steffler) writes:
> In article <e2BXZ1w163w@coyote.datalog.com> ferdie@coyote.datalog.com (fred jarvis) writes:
> >    I want to use a list structure in a Windows application.
> >Typically, something like
> >        typedef struct {
> >           datatype *data;
> >           listnode *next;
> >        } listnode;
> >would be used, with each node dynamically allocated.
> 
> Obviously this is a no-no in Windows, as you must allocate crap loads
> of pointers (ie. handles, then locked).  This would eat up the local handle
> table to the point where you run out of local heap space.  The same
> issue faces you with global memory handles.
[The rest of Glenns answer deleted]

Glenn has given a good description of the issues involved here.

Another way you can do this is to create a local heap in a separate
block of memory allocated by GlobalAlloc.  LocalInit will create
a local heap in that block for you.

Using such a block is not straightforward, you need to set DS to
the segment(selector) of the block before calling any Local
routines.

For example:

hHeap = GlobalAlloc(GMEM_MOVEABLE, 4096L);
segHeap = HIWORD(GlobalLock(hHeap));

LocalInit(segHeap,16,4095);

To alloc from this heap:

_asm	mov	SaveDS, ds;
_asm	mov	ds, segHeap;

hlocal = LocalAlloc(LMEM_FIXED, wBytes);

_asm	mov	ds, SaveDS;

(... far *)(hHeap<<16 + hlocal) will point to this object.

Using Microsoft's C6 based pointers would make referencing
objects in this heap easy.

A couple of notes:
When calling LocalInit, DO NOT use the first 16 bytes of
the object.
The End parameter to LocalIinit will be one less than
the size of the block you allocated.
Apologies for any syntax errors and the lack of typing
in my example.
The SaveDS, wBytes and hlocal variables must be local
ie. stack variables.

Tony Gosling.
Technical Details
Message-ID: <3714@polari.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uwm.edu!ogicse!milton!sumax!polari!tonyg
References: <e2BXZ1w163w@coyote.datalog.com> <1991Apr5.205519.29757@sunee.waterloo.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uwm.edu!ogicse!milton!sumax!polari!tonyg
From: tonyg@polari.UUCP (Tony Gosling)
Newsgroups: comp.windows.ms.programmer
Subject: Re: How to best represent a list in Windows?
Summary: Using LocalInit for private memory allocation
Message-ID: <3714@polari.UUCP>
Date: 10 Apr 91 06:09:12 GMT
References: <e2BXZ1w163w@coyote.datalog.com> <1991Apr5.205519.29757@sunee.waterloo.edu>
Organization: Seattle Online Public Unix (206) 328-4944
Lines: 58