Article View: comp.windows.ms.programmer
Article #1157GlobalAlloc and arrays > 64k
From: Donald Doherty
Date: Mon, 28 Jan 1991 08:37
Date: Mon, 28 Jan 1991 08:37
65 lines
2410 bytes
2410 bytes
I allocated global memory for use by a three dimensional array
in the following way...
#define LTSTOP 605
#define NCLS 50
#define NCPOPS 3
.
.
static GLOBALHANDLE hPSomaMemory;
static GLOBALHANDLE hPSoma1Memory;
static GLOBALHANDLE hPSoma2Memory;
static GLOBALHANDLE hPSoma3Memory;
.
.
hPSomaMemory = GlobalAlloc (GMEM_MOVEABLE, NCPOPS * sizeof(int));
hPSoma1Memory = GlobalAlloc (GMEM_MOVEABLE, NCLS * LTSTOP * sizeof(int));
hPSoma2Memory = GlobalAlloc (GMEM_MOVEABLE, NCLS * LTSTOP * sizeof(int));
hPSoma3Memory = GlobalAlloc (GMEM_MOVEABLE, NCLS * LTSTOP * sizeof(int));
.
.
lpPSoma = (int FAR **) GlobalLock (hPSomaMemory);
lpPSoma[0] = (int FAR *) GlobalLock (hPSoma1Memory);
lpPSoma[1] = (int FAR *) GlobalLock (hPSoma2Memory);
lpPSoma[2] = (int FAR *) GlobalLock (hPSoma3Memory);
.
.
for (i = 0; i < NCPOPS; i++)
for (j = 0; j < NCLS; j++)
lpPSoma[i][j * LTSTOP + l] = ...;
It works but it seems rather messy. (However I do get a Warning at
compile time: segment lost in conversion. Any ideas why?) Is there
a better way to do this?
If I want **lpPSoma to point to an array containing four addresses to
arrays rather than three (or n addresses for that matter) I would
need four separate handles, one for each array.
I initially attempted to declare a huge int array as shown below.
int huge *lpPSoma;
.
.
hPSomaMemory = GlobalAlloc (GMEM_MOVEABLE, NCPOPS * NCLS * LTSTOP * sizeof(int));
.
.
for (i = 0; i < NCPOPS; i++)
for (j = 0; j < NCLS; j++)
lpPSoma[(i * NCLS * LTSTOP) + (j * LTSTOP) + l] =...;
This is much cleaner but crashes (run time, no compiler warnings)
when the array exceeds segment size (64k). I must be using it
incorrectly somehow.
I will be grateful for any help in using GlobalAlloc (and huge?)
correctly. I would eventually like to use MUCH larger arrays than
those that I am working with now.
Thank-you!
Don D.
ddoherty@ICS.uci.edu
Technical Details
Message-ID:
<27A3E2BD.25555@ics.uci.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!usc!orion.oac.uci.edu!ucivax!ddohertyShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!usc!orion.oac.uci.edu!ucivax!ddoherty From: ddoherty@ics.uci.edu (Donald Doherty) Newsgroups: comp.windows.ms.programmer Subject: GlobalAlloc and arrays > 64k Message-ID: <27A3E2BD.25555@ics.uci.edu> Date: 28 Jan 91 08:37:17 GMT Sender: ddoherty@ics.uci.edu (Donald Doherty) Organization: UC Irvine Department of ICS Lines: 65