CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: How to catch if buffer memory is full

    Quote Originally Posted by zerver
    Well, I can't realize something if I have no idea about how it's implemented. But you are right that I strongly suspect there is a penalty - otherwise it would be in widespread use among performance freaks such as me
    Check out Creating Guard Pages
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  2. #17
    Join Date
    Jun 2004
    Location
    India
    Posts
    432

    Re: How to catch if buffer memory is full

    Quote Originally Posted by zerver
    I have another question related to this:

    Are there any facilities for generating an interrupt when a specific memory address is written?

    For instance, if I have a vector class in which I add one element at a time and want to enter an interrupt routine when I write outside the allocated array. In this interrupt routine I need to reallocate the array to avoid a crash.

    The purpose would be to avoid having to check the bounds on each write, thus increasing performance slightly.

    I know a debugger can "break on memory write", but I suppose there is quite an overhead in using this technique. How does the debugger accomplish this?
    The way a debugger may implement 'break on memory write' is as follows

    1. Set the memory protection on the (virtual memory) page of interest.
    2. Trap the interrupt that is generated.
    3. Check if the specified memory address has been written; if yes break; else continue.

    I do not know if any CPU mechanism that can break on a specific memory address write. Breaking on a page basis is possible. This I suspect is the reason why 'break on this memory write' is not practically feasible - the thing would cause an interrupt on write to any of the memory addresses on that page and some other piece has to then check if the accesses memory is what someone wanted to be interrupted about; even with small page size (say 2K) that may be costly.
    Last edited by UnderDog; June 10th, 2008 at 02:35 PM. Reason: Realised that the information is already posted
    Say no to supplying ready made code for homework/work assignments!!

    Please rate this post!

  3. #18
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: How to catch if buffer memory is full

    Ah, excellent. Many thanks!

    This means that if you always make sure to allocate at least two pages more than you currently need and then set up the memory protection accordingly, this technique could actually be used to reallocate a growing array.

    And if I understand correctly, performance will not be negatively affected in this case since no other code will write to the protected page. When the interrupt is triggered you disable the protection, reallocate and finally protect the new page.

    At least the technique is interesting from a technical standpoint.
    Nobody cares how it works as long as it works

Page 2 of 2 FirstFirst 12

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