×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    14

    Exclamation Delete operator of a custom memory allocator

    I'm working on a custom memory allocator but the operator delete, redefined in a base class, is not called only on Symbian. Instead the global delete operator is called. This code is 100% pure C++ and I don't know way I receive the warning: "cannot find matching deallocation function for 'A'". I'm using the S60 3rd Edition MR SDK. What can I do to solve this issue?
    Code:
    #ifndef __SYMBIAN32__
    	#include <stdlib.h>
    #endif
    
    class A
    { 
    public:
    	virtual ~A() {} // A has descendents
    
    	#ifdef __SYMBIAN32__
    		void* operator new ( unsigned n, char* /*fileName*/, int /*line*/)	{ return User::Alloc( n); }
    		void operator delete( void* p) { User::Free( p); }
    		// tried also: void operator delete( void* p, unsigned /*s*/) { User::Free( p); }
    	#else
    		void* operator new ( unsigned n, char* /*fileName*/, int /*line*/)	{ return malloc( n); }
    		void operator delete( void* p) { free( p); }
    		// tried also: void operator delete( void* p, unsigned /*s*/) { free( p); }
    	#endif
    };
    
    void test()
    {
    	A* p = new (__FILE__, __LINE__) A();
    	delete p;
    };
    
    
    int main()
    {
    	test();
    	return 0;
    }
    I also made a DLL that exports the operators. Again I received at the compile time the same warning "cannot find matching deallocation function for 'A'". When I try to run an application that uses the DLL, the emulator gives an error "epoc.exe has triggered a breakpoint" and then it exits.

    Code:
            1    ??2A@@SAPAXIPADH@Z (public: static void * __cdecl A::operator new(unsigned int,char *,int))
            2    ??3A@@SAXPAX@Z (public: static void __cdecl A::operator delete(void *))
            3    ??3A@@SAXPAXI@Z (public: static void __cdecl A::operator delete(void *,unsigned int))

  2. #2
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Delete operator of a custom memory allocator

    As you provide placement new, you should provide placement delete too. As a simple test, just overload normal new/delete and see what happens.

  3. #3
    Registered User
    Join Date
    Apr 2005
    Location
    Barcelona
    Posts
    1,678

    Re: Delete operator of a custom memory allocator

    (In case you wonder, "placement delete" is called when an exception is thrown during object construction)

  4. #4
    Registered User
    Join Date
    Dec 2005
    Posts
    14

    Re: Delete operator of a custom memory allocator

    Thank's a lot! The problems is solved!

Similar Threads

  1. Overriding default memory allocator
    By dhaas in forum Symbian
    Replies: 2
    Last Post: 2006-10-24, 20:33
  2. Custom heap allocator?
    By dhaas in forum Symbian
    Replies: 6
    Last Post: 2006-09-29, 03:40
  3. Replies: 2
    Last Post: 2004-11-17, 10:20
  4. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29
  5. 9210 and 9210i java memory
    By allams in forum Mobile Java General
    Replies: 0
    Last Post: 1970-01-01, 02:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×