From: Christian Skluzacek (c.skluzacek++at++fokkerspace.nl)
Date: 01/18/2000 07:06:40
Xavier Decoret wrote:
> I am using Performer and I would like to reuse some geometric structures
> I designed some time ago.
> Unhappily, I am using the STL. The internal mechanism of allocation does
> not use pfMalloc and so I cannot share vector, list or association map.
> Ideally, the STL allows you to specify the allocation scheme but I can't
> make it work.
>
> Does anyone has done this before/knows a solution?
>
> Thanks.
>
Xavier,
Here's what I developed. I basically got the starting point from Musser
& Saini's STL Tutorial and Reference Guide for writing my own Allocator classes.
Chris
-
------------------------------------------------------------------------
Christian Skluzacek | FokkerSpace B.V.
Software Engineer | Newtonweg 1
Program Operations - Simulation | 2333 CP Leiden
+31 71 524 5718 | The Netherlands
mailto:c.skluzacek++at++fokkerspace.nl | http://www.fokkerspace.nl
------------------------------------------------------------------------
//============================================================================
// FILE NAME: pfShMemAlloc.H
// SYSTEM NAME:
// CONTENTS: pfShMemAlloc
//----------------------------------------------------------------------------
// KEYWORDS: $RCSfile: pfShMemAlloc.H,v $
// $Revision: 1.1 $
// $Date: 1999/11/17 12:32:55 $
// $Author: cs75474 $
//----------------------------------------------------------------------------
// HISTORY:
//
// Date Author Notes
// --------- ---------------- ----------------------------------------------
// 16Nov1999 C. Skluzacek Initial Implementation.
//
//============================================================================
#ifndef _pfShMemAlloc_H
#define _pfShMemAlloc_H __pfShMemAlloc_H
// -----------------
// Include Files
// -----------------
#ifdef _STANDARD_C_PLUS_PLUS
#include <iostream>
#include <memory>
using namespace std;
#else
#include <iostream.h>
#endif
#include <Performer/pr/pfMemory.h>
//============================================================================
// CLASS-NAME: pfShMemAlloc
// RELEASE: ALPHA
//----------------------------------------------------------------------------
// PURPOSE:
//
// Uses the Performer Shared Memory model for allocating memory to be used
// in conjunction with the Standard Template Library allocator scheme.
//
// NOTES:
// This file was adapted from the file: /usr/include/CC/stl_alloc.h
//
//----------------------------------------------------------------------------
// CROSS-REFERENCE:
//
// pfMemory, STL Allocators
//
//----------------------------------------------------------------------------
// HISTORY:
//
// Date Author Notes
// --------- ---------------- ----------------------------------------------
// 16Nov1999 C. Skluzacek Initial Implementation.
//
//============================================================================
template< class Type >
class pfShMemAlloc
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef Type* pointer;
typedef const Type* const_pointer;
typedef Type& reference;
typedef const Type& const_reference;
typedef Type value_type;
template <class OtherType> struct rebind {
typedef pfShMemAlloc<OtherType> other;
};
pfShMemAlloc() {}
pfShMemAlloc( const pfShMemAlloc & ) {}
template <class Type1> pfShMemAlloc(const pfShMemAlloc<Type1> & ) {}
~pfShMemAlloc() {}
pointer address(reference __x) const { return &__x; }
const_pointer address(const_reference __x) const { return &__x; }
// p_Size is permitted to be 0. The C++ standard says nothing about what
// the return value is when p_Size == 0.
Type* allocate(size_type p_Size, const void* = 0)
{
#ifdef DEBUG
cout << "pfShMemAlloc::allocate: " << p_Size<< ", " << sizeof(Type) << endl;
#endif
return p_Size != 0 ?
static_cast<Type*>(pfMemory::malloc(p_Size*sizeof(Type),pfGetSharedArena()))
: 0;
}
// p_tObject is not permitted to be a null pointer.
static void deallocate( pointer p_tObject, size_type p_Size )
{
#ifdef DEBUG
cout << "pfShMemAlloc::deallocate: " << p_Size << ", " << sizeof(Type)<< endl;
#endif
pfMemory::free( static_cast<void*>(p_tObject) );
}
static Type * reallocate( pointer p_tObject, size_type p_OldSize, size_type p_NewSize )
{
#ifdef DEBUG
cout << "pfShMemAlloc::reallocate: " << p_OldSize << ", " << p_NewSize << ", " << sizeof(Type)<< endl;
#endif
return reinterpret_cast<Type*>(pfMemory::realloc(static_cast<void*>(p_tObject),p_NewSize));
}
size_type max_size() const
{ return size_t(-1) / sizeof(Type); }
void construct( pointer p_pMem, Type & p_tObject )
{ new(p_pMem) Type(p_tObject); }
static void destroy( pointer p_tObject )
{ p_tObject->~Type(); }
}; // class pfShMemAlloc
#endif // _pfShMemAlloc_H DON'T ADD ANY LINES AFTER THIS ONE!!
This archive was generated by hypermail 2b29 : Tue Jan 18 2000 - 07:08:17 PST