RE: STL, custom allocators and Performer

New Message Reply Date view Thread view Subject view Author view

From: Arnott, Shane D (Shane.Arnott++at++Australia.Boeing.com)
Date: 03/29/2001 01:53:19


pfPeople,

In addition to this does anyone know how to track the usage of the
pfDataPool? Are there any tools to track how much memory is actually being
used and what is free etc?

-----Original Message-----
From: Arnott, Shane D
Sent: Thursday, March 29, 2001 5:34 PM
To: 'info-performer++at++sgi.com'
Subject: STL, custom allocators and Performer

Hi,
I've posted this topic to this forum before and thought I had a solution but
I seem to be getting some problems with memory leaks and over-writing
causing strange behaviour such as Illegal Instructions core dumps.

I'd like to know if anyone has written a SGI STL custom allocator that can
be used across unrelated processes. I have done so but it seems to crap over
my memory producing the core dumps. Due to it being a shared memory app
Purify isn't helping either.

My current allocator looks a like this (minus the standard bits):
-----
#include <Performer/pr/pfDataPool.h>

class SharedMemoryDataPool
{
        public:
                static pfDataPool * globalDataPool_;
};

template <class T>
   class DataPoolAllocator {
     public:
       // allocate but don't initialize num elements of type T
       pointer allocate (size_type num, const void* = 0) {
                   pointer ret =
(pointer)((pfDataPool*)SharedMemoryDataPool::globalDataPool_)->alloc(sizeof(
T),1);
           return ret;
       }
       // initialize elements of allocated storage p with value value
       void construct (pointer p, const T& value) {
           // initialize memory with placement new
           new((void*)p)T(value);
       }

       // destroy elements of initialized storage p
       void destroy (pointer p) {
           // destroy objects by calling their destructor
           p->~T();
       }

       // deallocate storage p of deleted elements
       void deallocate (pointer p, size_type num) {
           ((pfDataPool*)SharedMemoryDataPool::globalDataPool_)->free((void
*)p);
       }
   };
-----

This is something I got the one of the SGI guys to help me with that they
kicked out over night. Of interest it doesn't seem to work with vectors but
does with deques. Of note in the allocate function the variable of
size_type num is not used, would this be an issue?

Then for each of my classes I add this #define to make them "DataPool Shared
Memory enabled"
------
#define DATAPOOL_OBJECT_DEFINE(SharedMemoryObject)
\
public:
\
    void* operator new(size_t size, pfDataPool * dataPool, int id = 0)
\
    {
\
        void * ptr;
\
        if ((ptr = (void *)(dataPool->alloc((uint)size, id)))==NULL)
\
        {
\
            std::cerr << "Unable to new into Shared Arena Data Pool!" <<
std::endl; \
            ptr = ::operator new(size);
\
                ((SharedMemoryObject *)ptr)->dataPool_ = 0;
\
        }
\
        else
\
            ((SharedMemoryObject *)ptr)->dataPool_ = dataPool;
\
        return ptr;
\
    }
\
    void* operator new(size_t size)
\
    {
\
        void * ptr = ::operator new(size);
\
        std::cerr << "Warning: Standard ::new used on " <<
#SharedMemoryObject \
                                        << std::endl;
\
        ((SharedMemoryObject *)ptr)->dataPool_ = 0;
\
        return ptr;
\
    }
\
    void operator delete(void *ptr)
\
    {
\
        if (((SharedMemoryObject *)ptr)->dataPool_ != 0)
\
            ((SharedMemoryObject *)ptr)->dataPool_->free(ptr);
\
        else
\
            ::operator delete(ptr);
\
    }
\
protected:
\
    pfDataPool * dataPool_;

------

I'd be keen for people to look this over to see if I am doing something
funamentally wrong. And also to comment on why only some containers work
and specifically why deques do and vectors don't seem to.

Any assistance or comments would be great.
____________
Shane Arnott
Technical Lead, Systems Analysis Laboratory
Boeing Australia, 363 Adelaide St, Brisbane QLD 4001
Email: shane.d.arnott++at++boeing.com
Ph: +61 7 3306 3320
Mob: +61 (0)401715353
Fax: +61 7 3306 3640


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Mar 29 2001 - 01:53:32 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.