none
Constrained Execution Region (CER) - Memory allocation? RRS feed

  • Question

  • Hello

    I'm a bit confused about the restriction of allocation memory determined by the constrained execution region because this page specifies under the section: Constraints, that explicit allocations aren't allowed. But as far as i can see, in this example the allocation of myStruct is explicit.

    Well is now the example wrong or am I wrong?

    Another question arises in relation to that memory allocation restriction. I use Visual Studio 2010 and program a library with C++/CLI because i have a lot of Windows API calls. For those calls I'm utilizing the IJW layer also called C++ Interop as far as i know.

    The question now is, if i call for example the function SetupDiOpenClassRegKey which returns a handle to the opened registry key in case of success, the guidelines recommend the use of a SafeHandle. In this case the suitable would be the Microsoft::Win32::SafeHandles::SafeRegistryHandle.

    Now due to the restriction of memory allocation i can't use that, because i can't place it on the stack, so i would have to allocate it with gcnew which is forbidden. Is that right?

    Maybe you could help me out with a little example, how you would do that.

    Thanks & Greetings

    Monday, April 8, 2013 1:06 AM

Answers

  • Hi There,

    >>Well is now the example wrong or am I wrong?

    I have checked the example and the document, it seems that the CER will keep the allocation work well, so the example use CER to keep the allocation atomic. The stucture is 

                RuntimeHelpers.PrepareConstrainedRegions();
                try { }
                finally
                {
                    //......
                }

    They don't  against to each other, oppositely, the example illustrates the document.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Intel x86 Wednesday, April 10, 2013 3:29 PM
    Wednesday, April 10, 2013 2:47 PM
    Moderator
  • Hi there,

    >>So the restrictions apply only to CER's in a context of a Critical Finalizer then?

    Yes.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Intel x86 Wednesday, April 10, 2013 4:14 PM
    Wednesday, April 10, 2013 4:04 PM
    Moderator

All replies

  • Hi There,

    >>Well is now the example wrong or am I wrong?

    I have checked the example and the document, it seems that the CER will keep the allocation work well, so the example use CER to keep the allocation atomic. The stucture is 

                RuntimeHelpers.PrepareConstrainedRegions();
                try { }
                finally
                {
                    //......
                }

    They don't  against to each other, oppositely, the example illustrates the document.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Intel x86 Wednesday, April 10, 2013 3:29 PM
    Wednesday, April 10, 2013 2:47 PM
    Moderator
  • Hi Mr. Feng, thanks for your reply.

    So the restrictions apply only to CER's in a context of a Critical Finalizer then?

    From some little private experiments I know, that you still have to take care about an Out of Memory (OOM) condition.

    Best regards, Intel-x86

    Wednesday, April 10, 2013 3:35 PM
  • Hi there,

    >>So the restrictions apply only to CER's in a context of a Critical Finalizer then?

    Yes.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Intel x86 Wednesday, April 10, 2013 4:14 PM
    Wednesday, April 10, 2013 4:04 PM
    Moderator
  • Hello Mr. feng, thanks again for the quick reply.

    The usage of the CER's is now clear to me. I would really recommend to release an official statement, telling about the difference when used in the context of a Critical Finalizer and as a non-interruptable block.

    Best regards, Intel-x86

    Wednesday, April 10, 2013 4:18 PM
  • Hi there,

    >>I would really recommend to release an official statement

    I would like to suggest you submit this request on Uservoice site: http://visualstudio.uservoice.com/forums/121579-visual-studio 

    There is a dedicated team checks the ideas there.

    Thank you for your valuable suggestions.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, April 10, 2013 4:22 PM
    Moderator