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

    Debugging crash on start and using multiple heaps

    Some percent of the time, my program is crashing on startup, only in optimized mode.

    I know fairly well about static dynamic initialization order fiasco. It behaves exactly like that but my instrumentation seems to say it's being initialized the same as before and ought to be working.

    As far as I can tell there's just nothing not being initialized before the crash occurs that could cause some error.

    An idea I recently implemented was to use two heaps, the process heap and creating a new heap. I save a handle to the system heap and then create a smaller heap to use for system type allocations which last a long time so that I won't fragment the main heap too much. Can this be the issue? Is there some way to run a heap in the debug mode?

    Also, is there some way to have the program spit out info on what is being loaded as it loads it? It seems like a basic and obvious thing to want in cases like this, though I have never had cause to do so until now.

    ANy help greatly appreciated.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Debugging crash on start and using multiple heaps

    Quote Originally Posted by originalfamousjohnsmith View Post
    Some percent of the time, my program is crashing on startup, only in optimized mode.
    You can debug a release build by just turning on the debug symbols and rebuilding your application under the debugger.
    I know fairly well about static dynamic initialization order fiasco. It behaves exactly like that but my instrumentation seems to say it's being initialized the same as before and ought to be working.

    As far as I can tell there's just nothing not being initialized before the crash occurs that could cause some error.

    An idea I recently implemented was to use two heaps, the process heap and creating a new heap. I save a handle to the system heap and then create a smaller heap to use for system type allocations which last a long time so that I won't fragment the main heap too much. Can this be the issue? Is there some way to run a heap in the debug mode?
    No one knows anything about your application except what is stated in the title of the thread, and the crash could have nothing to do with "multiple heaps". Once you start getting into such detail, the only way anyone can help is if they have your source code, compile it, and run it themselves. It could be a simple uninitialized variable for all we know, and not have anything to do with what you stated
    Also, is there some way to have the program spit out info on what is being loaded as it loads it?
    Run in the debugger and look at the Output Window.

    Regards,

    Paul McKenzie

  3. #3

    Re: Debugging crash on start and using multiple heaps

    Code:
    heap = GetProcessHeap();
    systemHeap = HeapCreate(0, 10*1024*1024, 100*1024*1024);
    More specifically part of my question is if the above code is OK in the sense I can continue to use both heap and systemHeap to allocate memory.



    Again more specifically, as I said I've put output in every location I can see and checked anything that's global. Somehow I want to find more info about what it's initializing in what order at the dynamic static initialization stage. The order is undefined in the language itself, and seems to vary even with the same code, but there must be some setting to tell vc++ to output what obj it's loading at runtime so I can at least guess where the problem is.

  4. #4

    Re: Debugging crash on start and using multiple heaps

    Well, I finally found the issue.

    It looks like I use something before it gets created if things get initialized in certain order. I didn't suspect that location because it has been like that for eons and never acted up til now.

    I still wish someone had more info about finding out what module it's loading as it would be a beacon to quickly solve issues like this. I am not sure that info actually exists though.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Debugging crash on start and using multiple heaps

    Quote Originally Posted by originalfamousjohnsmith View Post
    but there must be some setting to tell vc++ to output what obj it's loading at runtime so I can at least guess where the problem is.
    There is no such thing. You have to write the code to output what object is being initialized.

    Is there some reason why you can't write your application differently so that this is not an issue?

    Regards,

    Paul McKenzie

  6. #6

    Re: Debugging crash on start and using multiple heaps

    Quote Originally Posted by Paul McKenzie View Post
    There is no such thing. You have to write the code to output what object is being initialized.

    Is there some reason why you can't write your application differently so that this is not an issue?

    Regards,

    Paul McKenzie
    It would be called not using C++, no matter what method you use debugging it will be an issue. There's a difference between being helpful and argumentative, and argumentative nonsense that doesn't answer any of my questions is not helpful or wanted.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Debugging crash on start and using multiple heaps

    Quote Originally Posted by originalfamousjohnsmith View Post
    There's a difference between being helpful and argumentative, and argumentative nonsense that doesn't answer any of my questions is not helpful or wanted.
    I just asked a question. Since I have no idea what your application is doing, what it looks like, etc. it leads to more questions.

    Also, there always is a way to get around static initialization problems. It may be easy or difficult to do, but there is always a workaround.

    Regards,

    Paul McKenzie

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured