         exit( -1 );
     } else if( m == PageAligned ) {
         void* ptr;
-        long  pagesize = sysconf(_SC_PAGESIZE);
-        int   retval = posix_memalign( &ptr, pagesize, sz );
-
+
+#ifdef _WIN32
+        ptr = _aligned_malloc(sz, GetPageSize());
+        if (ptr) return ptr;
+#else
+        int retval = posix_memalign( &ptr, GetPageSize(), sz );
         if( retval == 0 ) return ptr;
+#endif
 
 #ifdef _GNU_SOURCE
         char b[100];
         const char* buf = strerror_r( errno, b, 100 );
 #else
-        char buf[100];
-        strerror_r( errno, buf, 100 );
+        const char* buf = strerror(errno);
 #endif
         cerr << __FILE__ << ":" << __LINE__ << endl
              << "    Failed to allocate " << sz << " bytes of page-aligned host memory." << endl

    cudaError_t err;
    err = cudaFree( data );
    POP_CUDA_FATAL_TEST( err, "Failed to free CUDA memory: " );
}

__host__

__host__
void PlaneBase::freeHost2D( void* data, PlaneMapMode m )
{
    if (!data)
        return;
    if (m == CudaAllocated) {
        cudaFreeHost(data);
        return;
    }
    if (m == Unaligned) {
        free(data);
        return;
    }
    if (m == PageAligned) {
#ifdef _WIN32
        _aligned_free(data);
#else
        free(data);
#endif
        return;
    }
    assert(!"Invalid PlaneMapMode");
}

__host__
