int main (int argc, char *argv[])
{
    void *ptr;
    int err = 0;

    hbw_set_policy(HBW_POLICY_BIND);

    printf ("Allocating 400 KB with 1GB pages\n");
    err = hbw_posix_memalign_psize (&ptr,
                                    1073741824,
                                    409600,
                                    HBW_PAGESIZE_1GB);

    if (err) {
        fprintf(stderr, "ERROR: hbw_posix_memalign_size()\n");
    }
    if (!err) {
        memset (ptr, 0, 409600);
        printf ("Reallocing 100KB with 1GB pages\n");
        ptr = hbw_realloc (ptr, 102400);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR: hbw_realloc()\n");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 102400);
        printf ("Reallocing 1GB with 1GB pages\n");
        ptr = hbw_realloc (ptr, 1073741824);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR: hbw_realloc()");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 1073741824);
        printf ("Reallocing 1073742848 with 1GB pages\n");
        ptr = hbw_realloc (ptr, 1073742848);
        if (ptr == NULL) {
            fprintf(stderr, "ERROR:  hbw_realloc()\n");
            err = -1;
        }
    }
    if (!err) {
        memset (ptr, 0, 1073742848);
    }
    if (ptr) {
        hbw_free(ptr);
    }

    return err;
}
int main(int argc, char **argv)
{
    const size_t size = 512;
    char *default_str = NULL;
    char *hbw_str = NULL;
    char *hbw_hugetlb_str = NULL;
    int err = 0;

    default_str = (char *)malloc(size);
    if (default_str == NULL) {
        perror("malloc()");
        fprintf(stderr, "Unable to allocate default string\n");
        err = errno ? -errno : 1;
        goto exit;
    }
    hbw_str = (char *)hbw_malloc(size);
    if (hbw_str == NULL) {
        perror("hbw_malloc()");
        fprintf(stderr, "Unable to allocate hbw string\n");
        err = errno ? -errno : 1;
        goto exit;
    }
    err = hbw_posix_memalign_psize((void **)&hbw_hugetlb_str, 2097152, size, HBW_PAGESIZE_2MB);
    if (err) {
        perror("hbw_posix_memalign()");
        fprintf(stderr, "Unable to allocate hbw hugetlb string\n");
        err = errno ? -errno : 1;
        goto exit;
    }

    sprintf(default_str, "Hello world from standard memory\n");
    sprintf(hbw_str, "Hello world from high bandwidth memory\n");
    sprintf(hbw_hugetlb_str, "Hello world from high bandwidth 2 MB paged memory\n");

    fprintf(stdout, "%s", default_str);
    fprintf(stdout, "%s", hbw_str);
    fprintf(stdout, "%s", hbw_hugetlb_str);

exit:
    if (hbw_hugetlb_str) {
        hbw_free(hbw_hugetlb_str);
    }
    if (hbw_str) {
        hbw_free(hbw_str);
    }
    if (default_str) {
        free(default_str);
    }
    return err;
}