home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX0702.CPP
- //------------------------------------------------------------
- // Demonstration of new operator with placement feature
- //------------------------------------------------------------
-
- //------------------------------------------------------------
- // The Borland Turbo C++ compiler does not support the
- placement feature.
- // The Microsoft Visual C++ compiler implementation allows
- // placement only with an overloaded new operator.
- // This example does works only in the IBM CSet II version.
- //------------------------------------------------------------
- // To run this program on an OS/2 machine:
- // move to an OS/2 window
- // [type] cd:\EXAMPLES\EX0702I
- // where cd: is the drive of the CD-ROM
- //------------------------------------------------------------
-
- //------------------------------------------------------------
- // files in this example:
- // EX0702.CPP this file
- //------------------------------------------------------------
-
- #include <iostream.h> // for stream output
- #include <new.h> // for prototype of new operator
-
- void main()
- {
- // allocate 1024 bytes of memory in free store
- char* store = new char[sizeof(char) * 1024];
- // print the address of the allocated memory
- cout << (void*) store << endl;
- // ...
- int size = 256;
- // ...
- // create an array of 256 integers at the location store
- int* buf = new( store ) int[size];
- // print the address of the array of integers
- cout << (void*) buf << endl;
- // the value of buf equal the value of store
- };
-