home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 21
/
CD_ASCQ_21_040595.iso
/
dos
/
graphic
/
font3d11
/
f3d_src
/
array.h
next >
Wrap
C/C++ Source or Header
|
1994-09-14
|
4KB
|
110 lines
//=================================================================================================
// Array.H
//
// Copyright (c) 1994 by Todd A. Prater
// All rights reserved.
//
//-------------------------------------------------------------------------------------------------
//
// An array class that allows for sizes larger than 64K. This is only here because it was the
// simplest way to get large arrays on MSDOS machines. I'm on the lookout for better ones...
//
// Constructor:
//
// ARRAY<T>(ULONG size, ULONG segSize) Creates an array with 'size' objects of type 'T'.
// 'segSize' is the maximum number of bytes that can
// be allocated at one time. For MSDOS machines this
// is 64K. The default value of 64000L is somewhat
// arbitrary; I'm not quite sure what a good value
// would be...
//
// Destructor:
//
// ~ARRAY(void)
//
// Member functions:
//
// Size(void) Returns the number of objects in the array.
//
// Operators:
//
// [] Array subscript operator.
//
//
//=================================================================================================
#ifndef __Array_H__
#define __Array_H__
#include <stddef.h>
#include <stdlib.h>
#include <fstream.h>
#include "Config.H"
template <class T>
class ARRAY
{
private: ULONG size;
ULONG numOfSegs;
ULONG objsPerSeg;
T** segArray;
public: ARRAY(ULONG _size, ULONG segSize=64000L)
{
ULONG objectSize = sizeof(T);
size = _size;
objsPerSeg = segSize/objectSize;
numOfSegs = size/objsPerSeg+1;
ULONG lastSegSize = size%objsPerSeg;
segArray = new T* [numOfSegs-1];
if (segArray==NULL)
{
cout<<"ERROR: Out of memory."<<endl;
exit(1);
}
for(ULONG i=0;i<numOfSegs-1;i++)
{
segArray[i] = new T[objsPerSeg-1];
if (segArray[i]==NULL)
{
cout<<"ERROR: Out of memory."<<endl;
exit(1);
}
}
segArray[i] = new T[lastSegSize-1];
if (segArray[i]==NULL)
{
cout<<"ERROR: Out of memory."<<endl;
exit(1);
}
}
~ARRAY(void)
{
for (ULONG i=0;i<numOfSegs;i++)
delete segArray[i];
delete segArray;
}
T& operator [] (ULONG index)
{
if (index >= size )
{
cout<<"ERROR: Out of range."<<endl;
exit(1);
}
T& tempT = segArray[index/objsPerSeg][index%objsPerSeg];
return tempT;
}
ULONG Size(void) { return size; }
};
#endif