home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / os / msdos / programm / 9267 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.4 KB  |  76 lines

  1. Xref: sparky comp.os.msdos.programmer:9267 comp.lang.c++:13527
  2. Newsgroups: comp.os.msdos.programmer,comp.lang.c++
  3. Path: sparky!uunet!usc!rpi!ghost.dsi.unimi.it!cdc835.cdc.polimi.it!gin503
  4. From: gin503@cdc835.cdc.polimi.it (Maurizio Sartori Masar)
  5. Subject: BC++ far new(): Results
  6. Date: Fri, 11 Sep 1992 09:04:41 GMT
  7. Nntp-Posting-Host: cdc835.cdc.polimi.it
  8. Organization: C.d.C., Politecnico di Milano
  9. Sender: netnews@cdc835.cdc.polimi.it (News Admin)
  10. Message-ID: <gin503.716202281@cdc835>
  11. Lines: 63
  12.  
  13.  
  14. Thanks to all who replyed.
  15.  
  16.  
  17. This is what I've discovered about using 'new' in small memory model with
  18. Borland C++.
  19.  
  20.  
  21. /***************************************/
  22. /* Uncomment the Case you want examine */
  23. /***************************************/
  24.  
  25. //                                  // Case | Class | New  |  Result
  26. //                                  //      |  Def  | Call |
  27. //                                  // ----------------------------------------
  28. //#define FOO_DEF        FOO        //  1   |  near |      |
  29. //#define FOO_NEW        FOO        //  1   |       | near |  near alloc
  30. //#define FOO_DEF   far  FOO        //  2   |  far  |      |
  31. //#define FOO_NEW        FOO        //  2   |       | near |  near alloc
  32. //#define FOO_DEF        FOO        //  3   |  near |      |
  33. //#define FOO_NEW   far  FOO        //  3   |       | far  |  Compile error
  34. //#define FOO_DEF   far  FOO        //  4   |  far  |      |
  35. //#define FOO_NEW   far  FOO        //  4   |       | far  |  far  alloc
  36. //#define FOO_DEF   far  FOO        //  5   |  far  |      |
  37. //#define FOO_NEW  (far  FOO)       //  5   |       | far  |  Compile Error
  38.  
  39. #include <stdio.h>
  40.  
  41. class FOO_DEF
  42.    {
  43.    char cFoo [10000];
  44.    };  /* end-class FOO */
  45.  
  46. int main ()
  47.    {
  48.    FOO far * alpFoo [10];
  49.  
  50.    for (int i = 0; i < 10; i++)
  51.       {
  52.       alpFoo[i] = new FOO_NEW;
  53.  
  54.       printf ("Array %i is %Fp\n", i, alpFoo[i]);
  55.       }
  56.    return (0);
  57.    }
  58.  
  59.  
  60. /****************************/
  61.  
  62. Results: If you declare a class as 'far', you can alloc it 'near' or 'far'
  63.          as you want.
  64.          If you declare it 'near' you must alloc it 'near'.
  65.  
  66. Note: Don't use parentesis with the 'new' operator: Compiler error.
  67.  
  68.  
  69.                         Maurizio
  70.  
  71. --
  72.   ))    ))    ))      ))))))    ))    )))))))      Maurizio Sartori Masar
  73.   ))))))))  ))  ))   ))))))   ))  ))  ))    ))   gin503@cdc835.cdc.polimi.it
  74.   )) )) )) ))))))))       )) )))))))) ))))))       Politecnico di Milano
  75.   ))    )) ))    ))  ))))))  ))    )) ))    ))            ITALY
  76.