home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / msdos / programm / 8181 < prev    next >
Encoding:
Text File  |  1992-07-30  |  3.2 KB  |  136 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!sun-barr!decwrl!csus.edu!netcomsv!mork!resnicks
  3. From: resnicks@netcom.com (Steve Resnick)
  4. Subject: Re: far struct - how to do it ?
  5. Message-ID: <czpmbhl.resnicks@netcom.com>
  6. Date: Thu, 30 Jul 92 16:58:30 GMT
  7. Organization: What? Me organized? You should see my checkbook!
  8. References: <1992Jul29.125835.14342@msc.cornell.edu>
  9. Distribution: comp.os.msdos.programmer
  10. Lines: 124
  11.  
  12. In article <1992Jul29.125835.14342@msc.cornell.edu> revesz@msc.cornell.edu (Peter Revesz) writes:
  13. >Hi, Netters,
  14. >
  15. >My global data is basicly in structures. To avoid
  16. >compile-time error message (global data >64 Kb) I have
  17. >to make all global far.
  18. >
  19. >How to make a struct far?
  20. >
  21. >This way:
  22. >
  23. >struct one {
  24. >    int far a[100];
  25. >    double far b[2000];
  26. >} one;
  27. >
  28. >or this way:
  29. >
  30. >struct two {
  31. >    int a[100];
  32. >    double b[2000];
  33. >} far two;
  34. >
  35. >
  36. >or this way?
  37. >
  38. >struct three {
  39. >    int far a[100];
  40. >    double far b[2000];
  41. >} far three;
  42. >
  43. >
  44. >Which the proper way to create far structs?
  45. >Any help will be appreciated.
  46. >
  47. >Peter Revesz
  48. >
  49. >revesz@msc.cornell.edu
  50.  
  51. > Hi, Netters,
  52. > My global data is basicly in structures. To avoid
  53. > compile-time error message (global data >64 Kb) I have
  54. > to make all global far.
  55. > How to make a struct far?
  56. > This way:
  57. > struct one {
  58. >     int far a[100];
  59. >     double far b[2000];
  60. > } one;
  61. >
  62. This won't work - the data being delcared is static, which will still
  63. result in the same error message.
  64.  
  65. > or this way:
  66. > struct two {
  67. >     int a[100];
  68. >     double b[2000];
  69. > } far two;
  70. > or this way?
  71. > struct three {
  72. >     int far a[100];
  73. >     double far b[2000];
  74. > } far three;
  75. > Which the proper way to create far structs?
  76. > Any help will be appreciated.
  77.  
  78. How about:
  79.  
  80. struct foo {
  81.     int *a;
  82.     double *b;
  83. } bar;
  84.     .
  85.     .
  86.     .
  87.     if ((bar.a = calloc(sizeof(int),100)) == NULL)
  88.         .
  89.         .
  90.         .
  91.     if ((bar.b = calloc(sizeof(double),2000)) == NULL)
  92.         .
  93.         .
  94.         .
  95.  
  96.  
  97. For one thing the far keyword is not portable, and is implementation dependant.
  98. the meathod I have showed you is portable, and will work with ANSI C.
  99.  
  100.  
  101. In 8086 real mode and 80286 protected mode, the processor's maximum memory
  102. allocation unit is a 64K segment. (except in huge model where the compiler
  103. generates the code necessary to 'tile' segments). When you compile your code,
  104. static data goes in a single segment, DGROUP. If, at compile time, the static
  105. data consists of pointers rather than the actual arrays, then the DGROUP
  106. is smaller. If you are compiling under medium or large memory models,
  107. you can allocate almost 64K per item, provided there is enough available
  108. memory on the far heap. If you are using the compact, or small models,
  109. you can add the far keyword in front of your pointer declarations and use
  110. farcalloc (or farmalloc) to get memory.
  111.  
  112.  
  113.  
  114. Hope this helps ....
  115.  
  116.  
  117. Steve
  118.  
  119. -- 
  120. ------------------------------------------------------------------------------
  121. Steve Resnick - resnicks@netcom.com steve@axebbs.kludge.com FidoNet: 1:143/105
  122. "I just want to be the one you run to, I just want to be the one you come to.
  123. I just want to be there for someone, when the night comes" - J. Cocker
  124. -----------------------------------------------------------------------------
  125.