static int test_Buffer (){ cout << "Go Testing" << __FILE__ << endl; MemoryPool pool; Buffer buffer( &pool, 10); buffer.copy ( "hellohelloX", 11); // too big, will not copy cout << (char*)buffer.data () << "," << buffer.size () << "," << buffer.capacity () << endl; buffer.copy ( "world", 5); cout << (char*)buffer.data () << "," << buffer.size () << "," << buffer.capacity () << endl; Buffer otherBuffer (buffer); cout << (char*)otherBuffer.data () << "," << otherBuffer.size () << "," << otherBuffer.capacity () << endl; pool.clear (); cout << "test RingBuffer" << endl; RingBuffer ringBuffer( &pool, 3); int rs = 0; rs = ringBuffer.copy ("hel", 3); DLog("copied:", rs, (char*)ringBuffer.data () ); rs = ringBuffer.copy ("worldp", 6); DLog("copied:", rs, (char*)ringBuffer.data ()); rs = ringBuffer.copy ("worldpq", 7); DLog("copied:", rs, (char*)ringBuffer.data ()); cout << "capacity:" << ringBuffer.capacity () << "=>" << (char*)ringBuffer.data () << endl; return 0; }
static int test_MemoryPool (){ cout << "Go Testing" << __FILE__ << endl; MemoryPool pool; auto ptr1 = pool.alloc (5); auto ptr2 = pool.alloc (10); auto ptr3 = pool.alloc (11); pool.dump (); pool.free (ptr1); pool.free (ptr2); pool.dump (); int* ptr4 = (int*)ptr3; // ptr4++; // error !! pool.free ( (void*&)ptr4 ); // clear cout << "clear" << endl; pool.dump (); pool.clear (); pool.dump (); cout << "clear done." << endl; // for c++ A* a = pool.cnew<A>(); pool.dump (); pool.cdelete<A>(a); pool.dump (); cout << "a=>" << a << endl; return 0; }