Need help with using allocator in libstdc++

Jim Foley jfoley@quickturn.com
Tue Aug 17 15:50:00 GMT 1999


    Hello,

         I am at wit's end trying to make a small testcase using a custom allocator
    work.  The testcase below fails with both the libstdc++ released with gcc 2.95.1
    as well as libstdc++-2.90.6.   (This does work correctly with egcs-2.90.29 980515
    (egcs-1.0.3 release)).

         Can anyone suggest how to fix the testcase to make it work?

         Thanks in advance for your help,

                                                            - Jim Foley
                                                               Cadence Design Systems
                                                               foley@shore.net


#include <stddef.h>
#include <iostream.h>
#include <list.h>


struct IntPair
{
    int _a;
    int _b;
    IntPair(int a, int b)
        : _a(a), _b(b)
    { ; }
};



class MyAlloc : public alloc
{
public:

    MyAlloc()
    { ; }
    static void* allocate(size_t numBytes)
    { return malloc(numBytes); }
    static void deallocate(void*, size_t)
    { /* do nothing */ ; }

};  // end of class MyAlloc


int main()
{
    list<IntPair, MyAlloc> myList;

    cout << "Testing..." << endl;

    myList.push_back(IntPair(4, 5));
    myList.push_back(IntPair(7, 8));
    myList.push_back(IntPair(123, 4895));

    cout << "Done!" << endl;

    return 0;

}






More information about the Libstdc++ mailing list