home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / mswindo / programm / misc / 4698 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.5 KB  |  67 lines

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. From: chris@chrism.demon.co.uk (Chris Marriott)
  3. Path: sparky!uunet!pipex!demon!chrism.demon.co.uk!chris
  4. Subject: Re: Big Global Arrays in DLL's? (Borland C) 
  5. Distribution: world
  6. References: <bsm.9.0@utrcv1.res.utc.com>
  7. Organization: None
  8. Reply-To: chris@chrism.demon.co.uk
  9. X-Mailer: Simple NEWS 1.90 (ka9q DIS 1.19)
  10. Lines: 52
  11. Date: Wed, 6 Jan 1993 20:39:10 +0000
  12. Message-ID: <726352750snz@chrism.demon.co.uk>
  13. Sender: usenet@demon.co.uk
  14.  
  15. In article <bsm.9.0@utrcv1.res.utc.com> bsm@utrcv1.res.utc.com writes:
  16.  
  17. >I need to have a big (very big, maybe 300K) global array in a DLL.
  18. >
  19. >It seems to be telling me I can't have more than 32K in my global array.
  20. >
  21. >Is there any way I can do what I'm trying to?  I'm using Borland C.
  22. >
  23. >Thanks for any information!
  24. >---------------------------------------
  25. >Any opinions expressed here are mine alone,
  26. >and are not those of my employer or anyone else.
  27. >
  28. >Brian McCarthy
  29. >United Technologies Research Center
  30. >East Hartford, Connecticut
  31. >(203)727-7638
  32. >bsm@utrc.utc.com
  33. >---------------------------------------
  34. >
  35.  
  36. Any data which you declare global in an application of DLL goes into the
  37. default data segment which is limited to a total of 64k in size.  This 64k
  38. includes all global variables, strings, stack (in the case of an
  39. application, etc).
  40.  
  41. What you should do is have a *pointer* as a global variable, and allocate
  42. memory using the Windows global memory functions.
  43.  
  44. ie,
  45.     #include <windowsx.h>
  46.  
  47.     char huge *hpData;
  48.     hpData = (char huge *) GlobalAllocPtr( GMEM_MOVEABLE | GMEM_ZEROINIT,
  49.                                            300*1024 );
  50.  
  51. This will allocate a 300k array and store its address in the huge pointer
  52. "hpData".  Note, incidentally, that if you allocate a block of memory >128k
  53. in size and treat it as an array of items, each item must be an exact
  54. power of 2 bytes in size, otherwise you'll run into segment boundary problems.
  55.  
  56. GlobalAllocPtr is a macro in "windowsx.h".  It just does a "GlobalAlloc"
  57. followed by a "GlobalLock".  There's no problems with keeping memory locked
  58. in protected mode windows, so it's easier to do it this way.
  59. -- 
  60. --------------------------------------------------------------------------
  61. | Chris Marriott                           | chris@chrism.demon.co.uk    |
  62. | Warrington, UK                           | BIX: cmarriott              |
  63. | (Still awaiting inspiration              | CIX: cmarriott              |
  64. |  for a witty .sig .... )                 | CompuServe: 100113,1140     |
  65. --------------------------------------------------------------------------
  66.  
  67.