本文整理汇总了C++中HDmalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ HDmalloc函数的具体用法?C++ HDmalloc怎么用?C++ HDmalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HDmalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCurrRig
int
getCurrRig(int32 *pXdim, int32 *pYdim, char **pPalette, char **pRaster)
{
int ispal;
goTo(he_currDesc);
if (DFR8getdims(he_file, pXdim, pYdim, &ispal) < 0)
{
fprintf(stderr, "Error getting image group.\n");
HEprint(stderr, 0);
return FAIL;
}
if (ispal)
*pPalette = (char *) HDmalloc(HE_PALETTE_SZ);
else
*pPalette = (char *) NULL;
*pRaster = (char *) HDmalloc((size_t)(*pXdim) * (size_t)(*pYdim));
if (DFR8getimage(he_file, (unsigned char *) *pRaster, *pXdim, *pYdim,
(unsigned char *) *pPalette) == FAIL)
{
fprintf(stderr, "Error getting image group.\n");
HEprint(stderr, 0);
return FAIL;
}
return HE_OK;
}
示例2: split_box
PRIVATE VOID
split_box(struct box * ptr)
{
int dim, j, i;
float median;
struct box *l_child, *r_child;
dim = select_dim(ptr);
median = find_med(ptr, dim);
/* create 2 child */
l_child = (struct box *) HDmalloc(sizeof(struct box));
r_child = (struct box *) HDmalloc(sizeof(struct box));
for (i = RED; i <= BLUE; i++)
for (j = HI; j <= LO; j++)
{
l_child->bnd[i][j] = ptr->bnd[i][j];
r_child->bnd[i][j] = ptr->bnd[i][j];
}
l_child->bnd[dim][HI] = median;
r_child->bnd[dim][LO] = median;
classify(ptr, l_child);
classify(ptr, r_child);
r_child->right = ptr->right;
r_child->left = l_child;
l_child->right = r_child;
l_child->left = ptr->left;
(ptr->left)->right = l_child;
if (ptr->right != NULL)
(ptr->right)->left = r_child;
} /* end of split_box */
示例3: get_unique_name
static void
get_unique_name(void)
{
const char *prefix = NULL;
const char *env = HDgetenv("HDF5_PREFIX");
if (env)
prefix = env;
if (option_prefix)
prefix = option_prefix;
if (prefix)
/* 2 = 1 for '/' + 1 for null terminator */
filename = (char *) HDmalloc(HDstrlen(prefix) + HDstrlen(ZIP_PERF_FILE) + 2);
else
filename = (char *) HDmalloc(HDstrlen(ZIP_PERF_FILE) + 1);
if (!filename)
error("out of memory");
filename[0] = 0;
if (prefix){
HDstrcpy(filename, prefix);
HDstrcat(filename, "/");
}
HDstrcat(filename, ZIP_PERF_FILE);
}
示例4: test_encode_decode
static int
test_encode_decode(hid_t orig_pl, int mpi_rank, int recv_proc)
{
MPI_Request req[2];
MPI_Status status;
hid_t pl; /* Decoded property list */
size_t buf_size = 0;
void *sbuf = NULL;
herr_t ret; /* Generic return value */
if(mpi_rank == 0) {
int send_size = 0;
/* first call to encode returns only the size of the buffer needed */
ret = H5Pencode(orig_pl, NULL, &buf_size);
VRFY((ret >= 0), "H5Pencode succeeded");
sbuf = (uint8_t *)HDmalloc(buf_size);
ret = H5Pencode(orig_pl, sbuf, &buf_size);
VRFY((ret >= 0), "H5Pencode succeeded");
/* this is a temp fix to send this size_t */
send_size = (int)buf_size;
MPI_Isend(&send_size, 1, MPI_INT, recv_proc, 123, MPI_COMM_WORLD, &req[0]);
MPI_Isend(sbuf, send_size, MPI_BYTE, recv_proc, 124, MPI_COMM_WORLD, &req[1]);
} /* end if */
if(mpi_rank == recv_proc) {
int recv_size;
void *rbuf;
MPI_Recv(&recv_size, 1, MPI_INT, 0, 123, MPI_COMM_WORLD, &status);
buf_size = recv_size;
rbuf = (uint8_t *)HDmalloc(buf_size);
MPI_Recv(rbuf, recv_size, MPI_BYTE, 0, 124, MPI_COMM_WORLD, &status);
pl = H5Pdecode(rbuf);
VRFY((pl >= 0), "H5Pdecode succeeded");
VRFY(H5Pequal(orig_pl, pl), "Property List Equal Succeeded");
ret = H5Pclose(pl);
VRFY((ret >= 0), "H5Pclose succeeded");
if(NULL != rbuf)
HDfree(rbuf);
} /* end if */
if(0 == mpi_rank)
MPI_Waitall(2, req, MPI_STATUSES_IGNORE);
if(NULL != sbuf)
HDfree(sbuf);
MPI_Barrier(MPI_COMM_WORLD);
return(0);
}
示例5: nh5sselect_hyperslab_c
int_f
nh5sselect_hyperslab_c ( hid_t_f *space_id , int_f *op, hsize_t_f *start, hsize_t_f *count, hsize_t_f *stride, hsize_t_f *block)
{
int ret_value = -1;
hid_t c_space_id;
hsize_t *c_start = NULL;
hsize_t *c_count = NULL;
hsize_t *c_stride = NULL;
hsize_t *c_block = NULL;
H5S_seloper_t c_op;
herr_t status;
int rank;
int i;
rank = H5Sget_simple_extent_ndims(*space_id);
if (rank < 0 ) return ret_value;
c_start = (hsize_t *)HDmalloc(sizeof(hsize_t)*rank);
if (c_start == NULL) goto DONE;
c_count = (hsize_t *)HDmalloc(sizeof(hsize_t)*rank);
if (c_count == NULL) goto DONE;
c_stride = (hsize_t *)HDmalloc(sizeof(hsize_t)*rank);
if (c_stride == NULL) goto DONE;
c_block = (hsize_t *)HDmalloc(sizeof(hsize_t)*rank);
if (c_block == NULL) goto DONE;
/*
* Reverse dimensions due to C-FORTRAN storage order.
*/
for (i=0; i < rank; i++) {
int t= (rank - i) - 1;
c_start[i] = (hsize_t)start[t];
c_count[i] = (hsize_t)count[t];
c_stride[i] = (hsize_t)stride[t];
c_block[i] = (hsize_t)block[t];
}
c_op = (H5S_seloper_t)*op;
/*
if (*op == H5S_SELECT_SET_F) c_op = H5S_SELECT_SET;
if (*op == H5S_SELECT_OR_F) c_op = H5S_SELECT_OR;
*/
c_space_id = *space_id;
status = H5Sselect_hyperslab(c_space_id, c_op, c_start, c_stride, c_count, c_block);
if ( status >= 0 ) ret_value = 0;
DONE:
if(c_start != NULL) HDfree(c_start);
if(c_count != NULL) HDfree(c_count);
if(c_stride!= NULL) HDfree(c_stride);
if(c_block != NULL) HDfree(c_block);
return ret_value;
}
示例6: h5dread_vl_string_c
int_f
h5dread_vl_string_c( hid_t_f *dset_id , hid_t_f *mem_type_id, hid_t_f *mem_space_id, hid_t_f *file_space_id, hid_t_f *xfer_prp, _fcd buf, hsize_t_f *dims, size_t_f *len)
/******/
{
int ret_value = -1;
hid_t c_dset_id;
hid_t c_mem_type_id;
hid_t c_mem_space_id;
hid_t c_file_space_id;
hid_t c_xfer_prp;
herr_t status;
char *tmp, *tmp_p;
size_t max_len;
char **c_buf;
hsize_t i;
hsize_t num_elem;
max_len = (size_t)dims[0];
num_elem = (hsize_t)dims[1];
c_dset_id = (hid_t)*dset_id;
c_mem_type_id = (hid_t)*mem_type_id;
c_mem_space_id = (hid_t)*mem_space_id;
c_file_space_id = (hid_t)*file_space_id;
c_xfer_prp = (hid_t)*xfer_prp;
/*
* Allocate array of character pointers
*/
c_buf = (char **)HDmalloc((size_t)num_elem * sizeof(char *));
if (c_buf == NULL) return ret_value;
/*
* Call H5Dread function.
*/
status = H5Dread(c_dset_id, c_mem_type_id, c_mem_space_id, c_file_space_id, c_xfer_prp, c_buf);
if (status < 0) { HDfree(c_buf);
return ret_value;
}
/* Copy data to long C string */
tmp = (char *)HDmalloc((size_t)(max_len*num_elem) +1);
tmp_p = tmp;
for (i=0; i<max_len*num_elem; i++) tmp[i] = ' ';
tmp[max_len*num_elem] = '\0';
for (i=0; i < num_elem; i++) {
memcpy(tmp_p, c_buf[i], strlen(c_buf[i]));
len[i] = (size_t_f)strlen(c_buf[i]);
tmp_p = tmp_p + max_len;
}
HD5packFstring(tmp, _fcdtocp(buf), (size_t)(max_len*num_elem));
ret_value = 0;
H5Dvlen_reclaim(c_mem_type_id, c_mem_space_id, H5P_DEFAULT, c_buf);
HDfree(c_buf);
HDfree(tmp);
return ret_value;
}
示例7: init_table
/*-------------------------------------------------------------------------
* Function: init_table
*
* Purpose: allocate and initialize tables for shared groups, datasets,
* and committed types
*
* Return: void
*
* Programmer: Ruey-Hsia Li
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void
init_table(table_t **tbl)
{
table_t *table = (table_t *)HDmalloc(sizeof(table_t));
table->size = 20;
table->nobjs = 0;
table->objs = (obj_t *)HDmalloc(table->size * sizeof(obj_t));
*tbl = table;
}
示例8: trav_print_visit_lnk
/*-------------------------------------------------------------------------
* Function: trav_print_visit_lnk
*
* Purpose: Callback for visiting link, when printing info
*
* Return: 0 on success,
* -1 on failure
*-------------------------------------------------------------------------
*/
static int
trav_print_visit_lnk(const char *path, const H5L_info_t *linfo, void *udata)
{
trav_print_udata_t *print_udata = (trav_print_udata_t *)udata;
/* Print appropriate information for the type of link */
switch(linfo->type) {
case H5L_TYPE_SOFT:
if(linfo->u.val_size > 0) {
char *targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
if(targbuf) {
if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0)
targbuf[0] = 0;
printf(" %-10s %s -> %s\n", "link", path, targbuf);
HDfree(targbuf);
}
} /* end if */
else
printf(" %-10s %s ->\n", "link", path);
break;
case H5L_TYPE_EXTERNAL:
if(linfo->u.val_size > 0) {
char *targbuf = NULL;
const char *filename = NULL;
const char *objname = NULL;
targbuf = (char*)HDmalloc(linfo->u.val_size + 1);
if(targbuf) {
if(H5Lget_val(print_udata->fid, path, targbuf, linfo->u.val_size + 1, H5P_DEFAULT) < 0)
targbuf[0] = 0;
if(H5Lunpack_elink_val(targbuf, linfo->u.val_size, NULL, &filename, &objname) >= 0)
printf(" %-10s %s -> %s %s\n", "ext link", path, filename, objname);
HDfree(targbuf);
}
} /* end if */
else
printf(" %-10s %s ->\n", "ext link", path);
break;
case H5L_TYPE_HARD:
/* Should be handled elsewhere */
return(-1);
case H5L_TYPE_ERROR:
case H5L_TYPE_MAX:
default:
printf(" %-10s %s -> ???\n", "unknown type of UD link", path);
break;
} /* end switch() */
return(0);
} /* end trav_print_visit_lnk() */
示例9: test_plists
static int
test_plists(const char *filename1, const char *filename2)
{
int fd_le, fd_be;
size_t size_le = 0, size_be = 0;
void *buf_le = NULL, *buf_be = NULL;
hid_t plist_le, plist_be; /* dataset create prop. list */
const char *testfile;
testfile = H5_get_srcdir_filename(filename1);
if((fd_le = HDopen(testfile, O_RDONLY, 0666)) < 0)
TEST_ERROR
size_le = HDlseek(fd_le, (HDoff_t)0, SEEK_END);
HDlseek(fd_le, (HDoff_t)0, SEEK_SET);
buf_le = (void *)HDmalloc(size_le);
if(HDread(fd_le, buf_le, size_le) < 0)
TEST_ERROR
HDclose(fd_le);
testfile = H5_get_srcdir_filename(filename2);
if((fd_be = HDopen(testfile, O_RDONLY, 0666)) < 0)
TEST_ERROR
size_be = HDlseek(fd_be, (HDoff_t)0, SEEK_END);
HDlseek(fd_be, (HDoff_t)0, SEEK_SET);
buf_be = (void *)HDmalloc(size_be);
if(HDread(fd_be, buf_be, size_be) < 0)
TEST_ERROR
HDclose(fd_be);
if((plist_le = H5Pdecode(buf_le)) < 0)
FAIL_STACK_ERROR
if((plist_be = H5Pdecode(buf_be)) < 0)
FAIL_STACK_ERROR
if(!H5Pequal(plist_le, plist_be))
FAIL_PUTS_ERROR("PLIST encoding/decoding comparison failed\n")
if((H5Pclose(plist_le)) < 0)
FAIL_STACK_ERROR
if((H5Pclose(plist_be)) < 0)
FAIL_STACK_ERROR
HDfree(buf_le);
HDfree(buf_be);
return 1;
error:
printf("***** Plist Encode/Decode tests FAILED! *****\n");
return -1;
}
示例10: read_dataset
/*
* This function opens all the datasets in a certain, checks the data using
* dataset_vrfy function.
*
* Changes: Updated function to use a dynamically calculated size,
* instead of the old SIZE #define. This should allow it
* to function with an arbitrary number of processors.
*
* JRM - 8/11/04
*/
int read_dataset(hid_t memspace, hid_t filespace, hid_t gid)
{
int i, j, n, mpi_rank, mpi_size, size, attr_errors=0, vrfy_errors=0;
char dname[32];
DATATYPE *outdata = NULL, *indata = NULL;
hid_t did;
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
size = get_size();
indata = (DATATYPE*)HDmalloc((size_t)(size * size * sizeof(DATATYPE)));
VRFY((indata != NULL), "HDmalloc succeeded for indata");
outdata = (DATATYPE*)HDmalloc((size_t)(size * size * sizeof(DATATYPE)));
VRFY((outdata != NULL), "HDmalloc succeeded for outdata");
for(n=0; n<NDATASET; n++) {
sprintf(dname, "dataset%d", n);
did = H5Dopen(gid, dname);
VRFY((did>0), dname);
H5Dread(did, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT,
indata);
/* this is the original value */
for(i=0; i<size; i++)
for(j=0; j<size; j++) {
*outdata = n*1000 + mpi_rank;
outdata++;
}
outdata -= size * size;
/* compare the original value(outdata) to the value in file(indata).*/
vrfy_errors = check_value(indata, outdata, size);
/* check attribute.*/
if( (attr_errors = read_attribute(did, is_dset, n))>0 )
vrfy_errors += attr_errors;
H5Dclose(did);
}
HDfree(indata);
HDfree(outdata);
return vrfy_errors;
}
示例11: DFgetcomp
int
DFgetcomp(int32 file_id, uint16 tag, uint16 ref, uint8 *image, int32 xdim,
int32 ydim, uint16 scheme)
{
CONSTR(FUNC, "DFgetcomp");
uint8 *buffer;
uint8 *in;
uint8 *out;
int32 cisize, crowsize, buflen, bufleft; /* bufleft: bytes left in buffer */
int32 i;
int32 totalread;
int32 n;
int32 aid;
if (!HDvalidfid(file_id) || !tag || !ref || xdim <= 0 || ydim <= 0 || !image)
HRETURN_ERROR(DFE_ARGS, FAIL);
/* put this call up here instead of in switch statement, to make the */
/* code easier to follow */
if (scheme == DFTAG_JPEG5 || scheme == DFTAG_GREYJPEG5
|| scheme==DFTAG_JPEG || scheme==DFTAG_GREYJPEG)
return (DFCIunjpeg(file_id, tag, ref, (VOIDP) image, xdim, ydim, (int16)scheme));
/* Only do this stuff for non-JPEG compressed images */
aid = Hstartread(file_id, tag, ref);
if (aid == FAIL)
HRETURN_ERROR(DFE_NOMATCH, FAIL);
if (Hinquire(aid, (int32 *) NULL, (uint16 *) NULL, (uint16 *) NULL, &cisize,
(int32 *) NULL, (int32 *) NULL, (int16 *) NULL, (int16 *) NULL) == FAIL)
return FAIL;
switch (scheme)
{
case DFTAG_RLE:
crowsize = xdim * 121 / 120 + 128; /* max size of a row */
buffer = (uint8 *) HDmalloc((uint32) cisize);
if (!buffer)
{
buffer = (uint8 *) HDmalloc((uint32) crowsize);
if (!buffer)
{
Hendaccess(aid);
HRETURN_ERROR(DFE_NOSPACE, FAIL)
} /* end if */
buflen = crowsize;
} /* end if */
示例12: nh5aget_name_c
/*----------------------------------------------------------------------------
* Name: h5aget_name_c
* Purpose: Call H5Aget_name to get attribute's name
* Inputs: attr_id - attribute identifier
* bufsize -size of the buffer
* Outputs: buf - buffer to hold the name
* Returns: 0 on success, -1 on failure
* Programmer: Elena Pourmal
* Thursday, August 12, 1999
* Modifications:
*---------------------------------------------------------------------------*/
int_f
nh5aget_name_c(hid_t_f *attr_id, size_t_f *bufsize, _fcd buf)
{
char *c_buf=NULL; /* Buffer to hold C string */
int_f ret_value=0; /* Return value */
/*
* Allocate buffer to hold name of an attribute
*/
if ((c_buf = HDmalloc((size_t)*bufsize +1)) == NULL)
HGOTO_DONE(FAIL);
/*
* Call H5Aget_name function
*/
if ((ret_value = (int_f)H5Aget_name((hid_t)*attr_id, (size_t)*bufsize, c_buf)) < 0)
HGOTO_DONE(FAIL);
/*
* Convert C name to FORTRAN and place it in the given buffer
*/
HD5packFstring(c_buf, _fcdtocp(buf), (size_t)*bufsize);
done:
if(c_buf) HDfree(c_buf);
return ret_value;
}
示例13: encode_plist
static int
encode_plist(hid_t plist_id, int little_endian, const char *filename_le, const char *filename_be)
{
int fd = 0; /* file descriptor */
herr_t ret = 0;
void *temp_buf = NULL;
size_t temp_size = 0;
ssize_t write_size;
/* first call to encode returns only the size of the buffer needed */
if((ret = H5Pencode(plist_id, NULL, &temp_size)) < 0)
assert(ret > 0);
temp_buf = (void *)HDmalloc(temp_size);
assert(temp_buf);
if((ret = H5Pencode(plist_id, temp_buf, &temp_size)) < 0)
assert(ret > 0);
if(little_endian)
fd = HDopen(filename_le, O_RDWR | O_CREAT | O_TRUNC, 0666);
else
fd = HDopen(filename_be, O_RDWR | O_CREAT | O_TRUNC, 0666);
assert(fd > 0);
write_size = HDwrite(fd, temp_buf, temp_size);
assert(write_size == (ssize_t)temp_size);
HDclose(fd);
HDfree(temp_buf);
return 1;
}
示例14: UNUSED
/*
* Class: hdf_hdf5lib_H5
* Method: H5Oget_comment
* Signature: (J)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_hdf_hdf5lib_H5_H5Oget_1comment
(JNIEnv *env, jclass clss, jlong loc_id)
{
jstring str = NULL;
ssize_t buf_size;
ssize_t status = -1;
char *oComment = NULL;
UNUSED(clss);
/* Get the length of the comment */
if ((buf_size = H5Oget_comment((hid_t)loc_id, NULL, 0)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
if (buf_size) {
if (NULL == (oComment = (char *) HDmalloc(sizeof(char) * (size_t)buf_size + 1)))
H5_JNI_FATAL_ERROR(ENVONLY, "H5Oget_comment: failed to allocate object comment buffer");
if ((status = H5Oget_comment((hid_t)loc_id, oComment, (size_t)buf_size + 1)) < 0)
H5_LIBRARY_ERROR(ENVONLY);
oComment[buf_size] = '\0';
if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oComment)))
CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE);
}
done:
if (oComment)
HDfree(oComment);
return (jstring)str;
} /* end Java_hdf_hdf5lib_H5_H5Oget_1comment */
示例15: getElement
int32
getElement(int desc, char **pdata)
{
int32 length;
int32 fid;
length = he_desc[desc].length;
/* alloc memory to read the element in */
*pdata = (char *) HDmalloc(length);
if (*pdata == NULL)
return FAIL;
/* read in the element and check for error */
if ((fid = Hopen(he_file, DFACC_READ, 0)) == 0)
{
HEprint(stderr, 0);
return FAIL;
}
if (Hgetelement(fid, he_desc[desc].tag, he_desc[desc].ref, (unsigned char *) (*pdata)) < 0)
{
HDfree(*pdata);
fprintf(stderr, "Cannot read element.\n");
return FAIL;
}
Hclose(fid);
return length;
}