mirror of
https://github.com/electronicarts/CnC_Renegade.git
synced 2025-12-16 07:31:40 -05:00
Initial commit of Command & Conquer Renegade source code.
This commit is contained in:
96
Code/Tests/mathtest/mempooltest.cpp
Normal file
96
Code/Tests/mathtest/mempooltest.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
** Command & Conquer Renegade(tm)
|
||||
** Copyright 2025 Electronic Arts Inc.
|
||||
**
|
||||
** This program is free software: you can redistribute it and/or modify
|
||||
** it under the terms of the GNU General Public License as published by
|
||||
** the Free Software Foundation, either version 3 of the License, or
|
||||
** (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
** GNU General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public License
|
||||
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/***********************************************************************************************
|
||||
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
|
||||
***********************************************************************************************
|
||||
* *
|
||||
* Project Name : MathTest *
|
||||
* *
|
||||
* $Archive:: /Commando/Code/Tests/mathtest/mempooltest.cpp $*
|
||||
* *
|
||||
* Author:: Greg Hjelstrom *
|
||||
* *
|
||||
* $Modtime:: 7/29/99 6:01p $*
|
||||
* *
|
||||
* $Revision:: 2 $*
|
||||
* *
|
||||
*---------------------------------------------------------------------------------------------*
|
||||
* Functions: *
|
||||
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
|
||||
|
||||
#include "mempool.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
class B : public AutoPoolClass<B,5>
|
||||
{
|
||||
public:
|
||||
// B(void) : AutoPoolClass<B,5>() { /*x = 2; y = 3;*/ }
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
class D
|
||||
{
|
||||
public:
|
||||
D(void);
|
||||
~D(void);
|
||||
|
||||
char * ptr;
|
||||
int x;
|
||||
};
|
||||
|
||||
D::D(void)
|
||||
{
|
||||
ptr = new char[500];
|
||||
x = 7;
|
||||
}
|
||||
D::~D(void)
|
||||
{
|
||||
delete[] ptr;
|
||||
x = 2;
|
||||
}
|
||||
|
||||
DEFINE_AUTO_POOL(B,5);
|
||||
ObjectPoolClass<D,5> DAllocator;
|
||||
|
||||
|
||||
|
||||
void test_mempool(void)
|
||||
{
|
||||
// allocate and delete a single 'B'
|
||||
B * test0 = new B;
|
||||
delete test0;
|
||||
|
||||
// allocate and delete a single 'D' make sure constructor
|
||||
// and destructor are called.
|
||||
D * test1 = DAllocator.Allocate_Object();
|
||||
DAllocator.Free_Object(test1);
|
||||
|
||||
#define NUM_OBJECTS 6
|
||||
B * Test[ NUM_OBJECTS ];
|
||||
int i;
|
||||
for ( i = 0; i < NUM_OBJECTS; i++ ) Test[i] = new B;
|
||||
for ( i = 0; i < NUM_OBJECTS; i++ ) printf( "%d) %p\n", i, Test[i] );
|
||||
for ( i = 0; i < NUM_OBJECTS; i++ ) delete Test[i];
|
||||
for ( i = 0; i < NUM_OBJECTS; i++ ) Test[i] = new B;
|
||||
for ( i = 0; i < NUM_OBJECTS; i++ ) printf( "%d) %p\n", i, Test[i] );
|
||||
for ( i = 0; i < NUM_OBJECTS; i++ ) delete Test[i];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user