276 lines
8.3 KiB
C++
276 lines
8.3 KiB
C++
#ifndef _ROCKALL_HPP_
|
|
#define _ROCKALL_HPP_
|
|
// Ruler
|
|
// 1 2 3 4 5 6 7 8
|
|
//345678901234567890123456789012345678901234567890123456789012345678901234567890
|
|
|
|
/********************************************************************/
|
|
/* */
|
|
/* The standard layout. */
|
|
/* */
|
|
/* The standard layout for 'hpp' files for this code is as */
|
|
/* follows: */
|
|
/* */
|
|
/* 1. Include files. */
|
|
/* 2. Constants exported from the class. */
|
|
/* 3. Data structures exported from the class. */
|
|
/* 4. Forward references to other data structures. */
|
|
/* 5. Class specifications (including inline functions). */
|
|
/* 6. Additional large inline functions. */
|
|
/* */
|
|
/* Any portion that is not required is simply omitted. */
|
|
/* */
|
|
/********************************************************************/
|
|
|
|
#include <stddef.h>
|
|
|
|
/********************************************************************/
|
|
/* */
|
|
/* Memory allocation constants. */
|
|
/* */
|
|
/* The memory allocation constants are denote special situations */
|
|
/* where optimizations are possible or failures have cccured. */
|
|
/* */
|
|
/********************************************************************/
|
|
|
|
const int AllocationFailure = 0;
|
|
const int GuardValue = 0xDeadBeef;
|
|
const int NoSize = -1;
|
|
|
|
/********************************************************************/
|
|
/* */
|
|
/* Class forward references. */
|
|
/* */
|
|
/* We need to refer to the following classes before they are */
|
|
/* fully specified so here we list them as forward references. */
|
|
/* */
|
|
/********************************************************************/
|
|
|
|
class CACHE;
|
|
class FIND;
|
|
class HEAP;
|
|
class NEW_PAGE;
|
|
|
|
/********************************************************************/
|
|
/* */
|
|
/* Linkage to the DLL. */
|
|
/* */
|
|
/* We need to compile the class specification slightly */
|
|
/* differently if we are creating the heap DLL. */
|
|
/* */
|
|
/********************************************************************/
|
|
|
|
#ifdef COMPILING_ROCKALL_DLL
|
|
#define ROCKALL_LINKAGE __declspec(dllexport)
|
|
#else
|
|
#define ROCKALL_LINKAGE __declspec(dllimport)
|
|
#endif
|
|
|
|
/********************************************************************/
|
|
/* */
|
|
/* The memory allocation interface. */
|
|
/* */
|
|
/* The memory allocator can be configured in a wide variety */
|
|
/* of ways to closely match the needs of specific programs. */
|
|
/* The interface outlined here can be overloaded to support */
|
|
/* whatever customization is necessary. */
|
|
/* */
|
|
/********************************************************************/
|
|
|
|
class ROCKALL_LINKAGE ROCKALL
|
|
{
|
|
public:
|
|
//
|
|
// Public types.
|
|
//
|
|
// A heap is constructed of a collection of
|
|
// fixed sized buckets each with an associated
|
|
// cache. The details of these buckets are
|
|
// supplied to the heap using the following
|
|
// structure.
|
|
//
|
|
typedef struct
|
|
{
|
|
int AllocationSize;
|
|
int CacheSize;
|
|
int ChunkSize;
|
|
int PageSize;
|
|
}
|
|
CACHE_DETAILS;
|
|
|
|
//
|
|
// Public data.
|
|
//
|
|
// The internals linkages in a heap are built
|
|
// dynamically during the execution of a heaps
|
|
// constructor. The member that follow relate
|
|
// to key internal classes.
|
|
//
|
|
CACHE **Array;
|
|
CACHE *Caches;
|
|
FIND *Find;
|
|
HEAP *Heap;
|
|
NEW_PAGE *NewPage;
|
|
|
|
//
|
|
// A heap constructor is required to preserve
|
|
// a small amount of information for the heap
|
|
// destructor.
|
|
//
|
|
bool GlobalDelete;
|
|
int GuardWord;
|
|
int NumberOfCaches;
|
|
int TotalSize;
|
|
|
|
//
|
|
// Public functions.
|
|
//
|
|
// A heaps public interface consists of a number
|
|
// of groups of related APIs.
|
|
//
|
|
ROCKALL( void );
|
|
|
|
ROCKALL
|
|
(
|
|
CACHE_DETAILS *Caches1,
|
|
CACHE_DETAILS *Caches2,
|
|
int FindCacheSize,
|
|
int FindCacheThreshold,
|
|
int FindSize,
|
|
int MaxFreeSpace,
|
|
int *NewPageSizes,
|
|
bool Recycle,
|
|
bool SingleImage,
|
|
int Stride1,
|
|
int Stride2,
|
|
bool ThreadSafe
|
|
);
|
|
|
|
//
|
|
// Manipulate allocations.
|
|
//
|
|
// The first group of functions manipulate
|
|
// single or small arrays of allocations.
|
|
//
|
|
virtual bool Delete
|
|
(
|
|
void *Address,
|
|
int Size = NoSize
|
|
);
|
|
|
|
virtual bool Details
|
|
(
|
|
void *Address,
|
|
int *Space = NULL
|
|
);
|
|
|
|
virtual bool KnownArea( void *Address );
|
|
|
|
virtual bool MultipleDelete
|
|
(
|
|
int Actual,
|
|
void *Array[],
|
|
int Size = NoSize
|
|
);
|
|
|
|
virtual bool MultipleNew
|
|
(
|
|
int *Actual,
|
|
void *Array[],
|
|
int Requested,
|
|
int Size,
|
|
int *Space = NULL,
|
|
bool Zero = false
|
|
);
|
|
|
|
virtual void *New
|
|
(
|
|
int Size,
|
|
int *Space = NULL,
|
|
bool Zero = false
|
|
);
|
|
|
|
virtual void *Resize
|
|
(
|
|
void *Address,
|
|
int NewSize,
|
|
int Move = -64,
|
|
int *Space = NULL,
|
|
bool NoDelete = false,
|
|
bool Zero = false
|
|
);
|
|
|
|
virtual bool Verify
|
|
(
|
|
void *Address = NULL,
|
|
int *Space = NULL
|
|
);
|
|
|
|
//
|
|
// Manipulate the heap.
|
|
//
|
|
// The second group of functions act upon a heap
|
|
// as a whole.
|
|
//
|
|
virtual void DeleteAll( bool Recycle = true );
|
|
|
|
virtual void LockAll( void );
|
|
|
|
virtual void Truncate( int MaxFreeSpace = 0 );
|
|
|
|
virtual void UnlockAll( void );
|
|
|
|
virtual bool Walk
|
|
(
|
|
bool *Active,
|
|
void **Address,
|
|
int *Space
|
|
);
|
|
|
|
//
|
|
// Low level heap interface.
|
|
//
|
|
// The third group of functions are called by the
|
|
// heap to aquire or release large blocks of memory.
|
|
// These functions can be overloaded to enable the
|
|
// heap work in constrained environments.
|
|
//
|
|
virtual void DeleteArea( void *Memory,int Size );
|
|
|
|
virtual int NaturalSize( void );
|
|
|
|
virtual void *NewArea( int AlignMask,int Size );
|
|
|
|
virtual ~ROCKALL( void );
|
|
|
|
//
|
|
// Public inline functions.
|
|
//
|
|
inline bool Available( void )
|
|
{ return (GuardWord == GuardValue); }
|
|
|
|
inline bool Failure( void )
|
|
{ return (GuardWord != GuardValue); }
|
|
|
|
private:
|
|
//
|
|
// Private functions.
|
|
//
|
|
// A heap needs to compute the size of certain
|
|
// user supplied structures. This task is
|
|
// performed by the following function.
|
|
//
|
|
int ComputeSize( char *Array,int Stride );
|
|
|
|
//
|
|
// Disabled operations.
|
|
//
|
|
// All copy constructors and class assignment
|
|
// operations are disabled.
|
|
//
|
|
ROCKALL( const ROCKALL & Copy );
|
|
|
|
void operator=( const ROCKALL & Copy );
|
|
};
|
|
#endif
|