CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Invoke AfxThrowMemoryException cause "Access Violation"

  1. #1
    Join Date
    Nov 2010

    Invoke AfxThrowMemoryException cause "Access Violation"

    I want to override the operator new in a class, as follows:

    class CMyclass
    void* operator new(size_t);
    void operator delete(void*);

    void* CMyclass:perator new(size_t size)
    void *p;

    p = MemoryManager.Alloc(size); // Using customized memory manager to allocate buffer

    if (NULL == p)

    However, in debug version, whenever MemoryManager.Alloc(size) returns NULL, which means alloation fails, the AfxThrowMemoryException will cause the following exception:

    Access violation reading location 0x#######

    How to fix the problem.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: Invoke AfxThrowMemoryException cause "Access Violation"

    Do you catch somewhere the CMemoryException?

    And please, edit your post adding the Code tags around code snippets!
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Iasi - Romania

    Re: Invoke AfxThrowMemoryException cause "Access Violation"

    Probably, the problem is inside MemoryManager::Alloc.
    Anyway, MFC has overloaded new operators, enough smart. So, it has no much sense to overload your own, with the risk to lead in headaches, like the one from OP.
    "When in Rome, do as Romans do."
    My latest articles:

Tags for this Thread

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)