home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- From: chris@chrism.demon.co.uk (Chris Marriott)
- Path: sparky!uunet!pipex!demon!chrism.demon.co.uk!chris
- Subject: Re: Big Global Arrays in DLL's? (Borland C)
- Distribution: world
- References: <bsm.9.0@utrcv1.res.utc.com>
- Organization: None
- Reply-To: chris@chrism.demon.co.uk
- X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
- Lines: 52
- Date: Wed, 6 Jan 1993 20:39:10 +0000
- Message-ID: <726352750snz@chrism.demon.co.uk>
- Sender: usenet@demon.co.uk
-
- In article <bsm.9.0@utrcv1.res.utc.com> bsm@utrcv1.res.utc.com writes:
-
- >I need to have a big (very big, maybe 300K) global array in a DLL.
- >
- >It seems to be telling me I can't have more than 32K in my global array.
- >
- >Is there any way I can do what I'm trying to? I'm using Borland C.
- >
- >Thanks for any information!
- >---------------------------------------
- >Any opinions expressed here are mine alone,
- >and are not those of my employer or anyone else.
- >
- >Brian McCarthy
- >United Technologies Research Center
- >East Hartford, Connecticut
- >(203)727-7638
- >bsm@utrc.utc.com
- >---------------------------------------
- >
-
- Any data which you declare global in an application of DLL goes into the
- default data segment which is limited to a total of 64k in size. This 64k
- includes all global variables, strings, stack (in the case of an
- application, etc).
-
- What you should do is have a *pointer* as a global variable, and allocate
- memory using the Windows global memory functions.
-
- ie,
- #include <windowsx.h>
-
- char huge *hpData;
- hpData = (char huge *) GlobalAllocPtr( GMEM_MOVEABLE | GMEM_ZEROINIT,
- 300*1024 );
-
- This will allocate a 300k array and store its address in the huge pointer
- "hpData". Note, incidentally, that if you allocate a block of memory >128k
- in size and treat it as an array of items, each item must be an exact
- power of 2 bytes in size, otherwise you'll run into segment boundary problems.
-
- GlobalAllocPtr is a macro in "windowsx.h". It just does a "GlobalAlloc"
- followed by a "GlobalLock". There's no problems with keeping memory locked
- in protected mode windows, so it's easier to do it this way.
- --
- --------------------------------------------------------------------------
- | Chris Marriott | chris@chrism.demon.co.uk |
- | Warrington, UK | BIX: cmarriott |
- | (Still awaiting inspiration | CIX: cmarriott |
- | for a witty .sig .... ) | CompuServe: 100113,1140 |
- --------------------------------------------------------------------------
-
-