fork(2) download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. struct MemoryManager
  5. {
  6. static void* allocate( unsigned size )
  7. {
  8. static char block[256];
  9. return block;
  10. }
  11. };
  12.  
  13. class Foo
  14. {
  15. public:
  16. void* operator new[]( size_t size )
  17. {
  18. std::cout << "operator new[] : data size -- " << size << std::endl;
  19. return MemoryManager::allocate( size );
  20. }
  21.  
  22. private:
  23. std::vector<long> m_dummy; // Huh?
  24. unsigned m_num;
  25. };
  26.  
  27. int main( int argc, char * argv[] )
  28. {
  29. std::cout << "Foo size: " << sizeof( Foo ) << std::endl;
  30. new Foo [4];
  31. Foo::operator new[]( 4 * sizeof( Foo ) );
  32. }
  33.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
Foo size: 16
operator new[] : data size -- 68
operator new[] : data size -- 64