home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX0702.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-30  |  1.6 KB  |  42 lines

  1. // \EXAMPLES\EX0702.CPP
  2. //------------------------------------------------------------
  3. // Demonstration of new operator with placement feature
  4. //------------------------------------------------------------
  5.  
  6. //------------------------------------------------------------
  7. // The Borland Turbo C++ compiler does not support the
  8.        placement feature.
  9. // The Microsoft Visual C++ compiler implementation allows
  10. //     placement only with an overloaded new operator.
  11. // This example does works only in the IBM CSet II version.
  12. //------------------------------------------------------------
  13. //  To run this program on an OS/2 machine:
  14. //                      move to an OS/2 window
  15. //              [type]  cd:\EXAMPLES\EX0702I
  16. //                      where cd: is the drive of the CD-ROM
  17. //------------------------------------------------------------
  18.  
  19. //------------------------------------------------------------
  20. // files in this example:
  21. // EX0702.CPP    this file
  22. //------------------------------------------------------------
  23.  
  24. #include <iostream.h>        // for stream output
  25. #include <new.h>             // for prototype of new operator
  26.  
  27. void main()
  28. {
  29.    // allocate 1024 bytes of memory in free store
  30.    char* store = new char[sizeof(char) * 1024];
  31.    // print the address of the allocated memory
  32.    cout << (void*) store << endl;
  33.    // ...
  34.    int size = 256;
  35.    // ...
  36.    // create an array of 256 integers at the location store
  37.    int* buf = new( store ) int[size];
  38.    // print the address of the array of integers
  39.    cout << (void*) buf << endl;
  40.    // the value of buf equal the value of store
  41. };
  42.