home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / cnr / cnralloc / cnralloc.cpp next >
Encoding:
C/C++ Source or Header  |  1996-10-29  |  2.9 KB  |  99 lines

  1. //************************************************************
  2. // Container Control - ICnrAllocator example
  3. //
  4. // Copyright (C) 1994, Law, Leong, Love, Olson, Tsuji.
  5. // Copyright (c) 1997 John Wiley & Sons, Inc. 
  6. // All Rights Reserved.
  7. //************************************************************
  8. #include <iframe.hpp>
  9. #include <icnrctl.hpp>
  10. #include <isplitcv.hpp>
  11. #include <iapp.hpp>
  12. #include <time.h>
  13.  
  14. void main ()
  15. {
  16.  
  17. // Create the frame window with a split canvas in the
  18. // client area.
  19. IFrameWindow frameWindow("Container ICnrAllocator Example");
  20. ISplitCanvas splitCanvas(0x101,
  21.                          &frameWindow,
  22.                          &frameWindow);
  23. frameWindow.setClient(&splitCanvas);
  24.  
  25. // Create two containers to go into the split canvas.
  26. IContainerControl::Style containerStyle = IContainerControl::classDefaultStyle
  27. #ifdef CCLCNR
  28.    | IContainerControl::pmCompatible
  29. #endif
  30.                                         | IContainerControl::noSharedObjects;
  31. IContainerControl slowContainer(0x102,
  32.                       &splitCanvas,
  33.                       &splitCanvas,
  34.                       IRectangle(),
  35.                       containerStyle);
  36. IContainerControl fastContainer(0x103,
  37.                       &splitCanvas,
  38.                       &splitCanvas,
  39.                       IRectangle(),
  40.                       containerStyle);
  41.  
  42. slowContainer
  43.   .showFlowedTextView()
  44.   .showTitle();
  45.  
  46. fastContainer
  47.   .showFlowedTextView()
  48.   .showTitle();
  49.  
  50. time_t startTime, endTime;
  51. IContainerObject* object;
  52.  
  53. // Test 1: Start the timer and add 5000 objects
  54. //         WITHOUT the allocator.
  55. time(&startTime);
  56. for(int i = 0; i<5000; i++)
  57. {
  58.    object = new IContainerObject("object");
  59.    slowContainer.addObject(object);
  60. }
  61.  
  62. // Stop the timer and change the text of the first
  63. // object to indicate the elapsed time.
  64. time(&endTime);
  65. double totalTime = difftime(endTime, startTime);
  66. IContainerObject* firstObject = slowContainer.objectAt(0);
  67. firstObject->setIconText(IString(totalTime)+" seconds");
  68. slowContainer
  69.   .setTitle(IString("Non-ICnrAllocator Container ")+IString(totalTime)+" seconds");
  70.  
  71.  
  72. // Test 2: Start the timer and add 5000 objects
  73. //         WITH the allocator.
  74. time(&startTime);
  75. ICnrAllocator allocator( 5000, sizeof(IContainerObject));
  76. for(int j = 0; j<5000; j++)
  77. {
  78.    object = new(allocator) IContainerObject("object");
  79. }
  80. fastContainer.addObjects(allocator);
  81.  
  82. // Stop the timer and change the text of the first
  83. // object to indicate the elapsed time.
  84. time(&endTime);
  85. totalTime = difftime(endTime, startTime);
  86. firstObject = fastContainer.objectAt(0);
  87. firstObject->setIconText(IString(totalTime)+" seconds");
  88.  
  89. fastContainer
  90.   .setTitle(IString("ICnrAllocator Container ")+IString(totalTime)+" seconds");
  91.  
  92.  
  93. // Give focus to the frame and show it.
  94. frameWindow.show();
  95. frameWindow.setFocus();
  96.  
  97. IApplication::current().run();
  98. }
  99.