Results 1 to 3 of 3

Thread: guard page

  1. #1
    Administrator Shelwien's Avatar
    Join Date
    May 2008
    Location
    Kharkov, Ukraine
    Posts
    3,915
    Thanks
    291
    Thanked 1,273 Times in 720 Posts

    guard page

    http://rextester.com/GSMTMH44081

    winapi has this feature which allows to mostly remove bound checks from compression algorithms,
    so I made a class which supposedly makes it easier to use.

    guard_buf< (1<<20) > buf;
    buf.init();
    for( j=0; j<3; j++ ) {
    GUARD_BEGIN(buf);
    for( i=0,p=buf;; i++ ) {
    *p++ = byte((i+j)>>0);
    *p++ = byte((i+j)>>8);
    *p++ = byte((i+j)>>16);
    *p++ = byte((i+j)>>24);
    if( buf.flag ) break;
    }
    GUARD_END(buf);
    uint x = (uint&)buf[buf.bufsize];
    printf( "x=%X i=%i/%i\n", x, i,buf.bufsize/4 );
    }

    The idea is that instead of explicit checks in the code, like if( p>=buf+bufsize) on each memory write,
    we can use hardware support (it has almost zero overhead when bound check is never triggered).

    "Guard page" is like normal memory, but triggers the SEH handler on first access, where buf.flag is set.
    Attached Files Attached Files

  2. Thanks (4):

    Bulat Ziganshin (21st September 2018),encode (7th November 2018),Gonzalo (20th September 2018),Mike (20th September 2018)

  3. #2
    Member
    Join Date
    Aug 2014
    Location
    Argentina
    Posts
    536
    Thanks
    238
    Thanked 90 Times in 70 Posts
    Performance impact? Do you know of any comparable features on other operating systems?

  4. #3
    Administrator Shelwien's Avatar
    Join Date
    May 2008
    Location
    Kharkov, Ukraine
    Posts
    3,915
    Thanks
    291
    Thanked 1,273 Times in 720 Posts
    > Performance impact?

    Well, it made my code a bit slower, but that's because I had to add memcpy for copying
    from guard_buf to actual output buffer.
    Branch prediction and __builtin_expect are pretty cool, too.

    But for a less optimized codec completely removing all bound checks should be helpful, right?
    For example, as an alternative, lzma has a special version of decoder ( "LzmaDec_TryDummy" ),
    which runs at the end of buffer to do bound checks.

    > Do you know of any comparable features on other operating systems?

    Linux (like Windows) also seems to use guard pages for stack growth, so it should be possible.
    See http://man7.org/linux/man-pages/man2/mprotect.2.html or google "linux guard page".

  5. Thanks:

    Bulat Ziganshin (21st September 2018)

Similar Threads

  1. any alternative to online page load stopwatch?
    By necros in forum The Off-Topic Lounge
    Replies: 5
    Last Post: 21st March 2016, 13:12
  2. JPEG renovating its web page
    By thorfdbg in forum Data Compression
    Replies: 2
    Last Post: 23rd October 2014, 11:02
  3. memstat: memory status and large page blocks available
    By Bulat Ziganshin in forum Download Area
    Replies: 2
    Last Post: 8th March 2013, 03:41
  4. PAQ8 - Download Page
    By Jan Ondrus in forum Data Compression
    Replies: 7
    Last Post: 7th October 2010, 21:14
  5. Compression Page
    By toffer in forum Data Compression
    Replies: 1
    Last Post: 28th July 2010, 23:13

Posting Permissions

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