本文整理汇总了C++中x_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ x_malloc函数的具体用法?C++ x_malloc怎么用?C++ x_malloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了x_malloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MibRegister
mib_object_t *
MibRegister( ul32 *Id, u16 IdLen, mib_callback_t Rqs, u16 Type, u16 Support, void *Param )
{
mib_object_t *object;
object = (mib_object_t *)x_malloc(sizeof(mib_object_t));
if (object == 0) {
x_dbg("XSNMP, MibRegister: object is 0\n", TRUE);
return 0;
}
if( !IdLen )
x_dbg("XSNMP, MibRegister: Idlen == 0\n", TRUE);
object->Id = (ul32 *)x_malloc(IdLen * sizeof(l32));
if (object->Id == 0) {
x_dbg("XSNMP, MibRegister: object->ID is 0\n", TRUE);
return 0;
}
x_memcpy(object->Id, Id, IdLen * sizeof(l32));
object->IdLen = IdLen;
object->Rqs = Rqs;
object->Type = Type;
object->Support = Support;
object->Param = Param;
if (!MibObjectInsert(object)) {
x_free(object->Id);
x_free(object);
x_dbg("XSNMP, MibRegister: MibObjectInsert fail\n", TRUE);
return 0;
}
return object;
}
示例2: apply_voronoi
void apply_voronoi (hf_wrapper_struct *hfw) {
// gint t1;
if (!hfw->hf_struct->tmp_buf)
hf_backup(hfw->hf_struct);
if (!hfw->hf_struct->result_buf)
hfw->hf_struct->result_buf =
(hf_type *) x_malloc(sizeof(hf_type) * hfw->hf_struct->max_x * hfw->hf_struct->max_y, "hf_type (result_buf in apply_voronoi)");
if (!hfw->hf_struct->tmp2_buf)
hfw->hf_struct->tmp2_buf =
(hf_type *) x_malloc(sizeof(hf_type) * hfw->hf_struct->max_x * hfw->hf_struct->max_y, "hf_type (tmp2_buf in apply_voronoi)");
// t1 = clock();
// Convention:
// 1. tmp_buf: original HF
// 2. tmp2_buf: distance HF
// 3. result_buf: crackled HF (base level + black lines == cracks)
// 4. hf_buf: output = crackled HF + distance HF (for lifting edges)
set_watch_cursor(hfw);
hf_voronoi(hfw->hf_struct, hfw->hf_options->img->voronoi);
voronoi_adjust_edges (hfw->hf_struct->result_buf, hfw->hf_struct->hf_buf, hfw->hf_struct->tmp2_buf, hfw->hf_options->img->voronoi->edges_level, hfw->hf_struct->max_x, hfw->hf_struct->max_y);
unset_watch_cursor(hfw);
// printf("TEMPS DE CRAQU�LEMENT: %d\n",clock() - t1);
}
示例3: verify_object
static int
verify_object(struct conf *conf, struct manifest *mf, struct object *obj,
struct hashtable *stated_files, struct hashtable *hashed_files)
{
for (uint32_t i = 0; i < obj->n_file_info_indexes; i++) {
struct file_info *fi = &mf->file_infos[obj->file_info_indexes[i]];
char *path = mf->files[fi->index];
struct file_stats *st = hashtable_search(stated_files, path);
if (!st) {
struct stat file_stat;
if (x_stat(path, &file_stat) != 0) {
return 0;
}
st = x_malloc(sizeof(*st));
st->size = file_stat.st_size;
st->mtime = file_stat.st_mtime;
st->ctime = file_stat.st_ctime;
hashtable_insert(stated_files, x_strdup(path), st);
}
if (fi->size != st->size) {
return 0;
}
if (conf->sloppiness & SLOPPY_FILE_STAT_MATCHES) {
if (fi->mtime == st->mtime && fi->ctime == st->ctime) {
cc_log("mtime/ctime hit for %s", path);
continue;
} else {
cc_log("mtime/ctime miss for %s", path);
}
}
struct file_hash *actual = hashtable_search(hashed_files, path);
if (!actual) {
struct mdfour hash;
hash_start(&hash);
int result = hash_source_code_file(conf, &hash, path);
if (result & HASH_SOURCE_CODE_ERROR) {
cc_log("Failed hashing %s", path);
return 0;
}
if (result & HASH_SOURCE_CODE_FOUND_TIME) {
return 0;
}
actual = x_malloc(sizeof(*actual));
hash_result_as_bytes(&hash, actual->hash);
actual->size = hash.totalN;
hashtable_insert(hashed_files, x_strdup(path), actual);
}
if (memcmp(fi->hash, actual->hash, mf->hash_size) != 0
|| fi->size != actual->size) {
return 0;
}
}
return 1;
}
示例4: args_init
struct args *
args_init(int init_argc, char **init_args)
{
struct args *args = (struct args *)x_malloc(sizeof(struct args));
args->argc = 0;
args->argv = (char **)x_malloc(sizeof(char *));
args->argv[0] = NULL;
for (int i = 0; i < init_argc; i++) {
args_add(args, init_args[i]);
}
return args;
}
示例5: create_file_info_index_map
static struct hashtable *
create_file_info_index_map(struct file_info *infos, uint32_t len)
{
struct hashtable *h =
create_hashtable(1000, hash_from_file_info, file_infos_equal);
for (uint32_t i = 0; i < len; i++) {
struct file_info *fi = x_malloc(sizeof(*fi));
*fi = infos[i];
uint32_t *index = x_malloc(sizeof(*index));
*index = i;
hashtable_insert(h, fi, index);
}
return h;
}
示例6: bignum_reverse
bignum_t * bignum_reverse (bignum_t * num) {
bignum_t * rev = x_malloc (sizeof (bignum_t));
bignum_init (rev);
rev->allocated = num->used;
rev->used = num->used;
rev->digits = x_malloc (rev->allocated);
for (size_t i = 0; i < num->used; i++)
rev->digits[i] = num->digits[num->used - 1 - i];
return rev;
}
示例7: conv_write_comms
static void conv_write_comms() {
int i, j;
int n, p, t;
/*MPI Communicators*/
for (i=0; i<numcomm; i++) {
if ( commtab[i].numbyte ) {
char *name = x_malloc(16 * sizeof(char));
unsigned int *array;
int num = 0;
for (j=0; j<(commtab[i].numbyte*8); j++) {
if ( (1 << (j % 8)) & commtab[i].bits[j/8] ) num++;
}
if (num) commtab[i].array = array = x_malloc(num * sizeof(unsigned int));
num = 0;
for (j=0; j<(commtab[i].numbyte*8); j++) {
if ( (1 << (j % 8)) & commtab[i].bits[j/8] )
array[num++] = get_comm_loc(j);
}
commtab[i].numarray = num;
if ( commtab[i].mode & ELG_GROUP_FLAG )
sprintf(name, "group %d", i);
else
sprintf(name, "comm %d", i);
if (num) wbytes += VTF3_WriteDefcpugrp(fcb, ++grpid, num, array, name);
}
}
/*OpenMP Thread Groups*/
if ( isthreaded ) {
for (n=0; n<machine[0].num_member; n++) {
Group *node = machine[0].member + n;
for (p=0; p<node->num_member; p++) {
Group *proc = node->member + p;
char *name = x_malloc(16 * sizeof(char));
unsigned int *array = x_malloc(proc->num_member * sizeof(unsigned int));
for (t=0; t<proc->num_member; t++) {
array[t] = proc->member[t].id;
}
sprintf(name, "tgroup %d", /*maxcomm + 1 +*/ proc->id);
wbytes += VTF3_WriteDefcpugrp(fcb, ++grpid, proc->num_member,
array, name);
}
}
}
}
示例8: copy_tab_minus_one
int copy_tab_minus_one(char ***dest, char **src, int index)
{
int cnt;
int tmp;
int cnt_max;
cnt = tmp = 0;
while (src[cnt] != '\0')
cnt++;
cnt_max = cnt;
if ((*dest = x_malloc(sizeof(**dest) * (cnt))) == NULL)
return (0);
cnt = 0;
while (cnt <= cnt_max)
{
if (((*dest)[tmp++] = my_strdup(src[cnt++])) == NULL)
return (0);
if (cnt == index)
cnt++;
if (cnt >= cnt_max)
{
(*dest)[tmp] = '\0';
return (0);
}
}
(*dest)[tmp] = '\0';
return (1);
}
示例9: x_malloc
error *errorReply(error *in_error, int in_reply_code, const char *in_text, ...)
{
error *toRet = x_malloc(sizeof(error), errorFree);
if (toRet)
{
memset(toRet, 0, sizeof(error));
toRet->m_code = in_reply_code;
if (in_error)
{
toRet->m_next = in_error->m_next;
in_error->m_next = NULL;
}
va_list v;
va_start(v, in_text);
vasprintf(&toRet->m_string, in_text, v);
va_end(v);
}
else
return &errorDefault;
return toRet;
}
示例10: init_log
static bool
init_log(void)
{
extern struct conf *conf;
if (debug_log_buffer || logfile || use_syslog) {
return true;
}
assert(conf);
if (conf->debug) {
debug_log_buffer_capacity = DEBUG_LOG_BUFFER_MARGIN;
debug_log_buffer = x_malloc(debug_log_buffer_capacity);
debug_log_size = 0;
}
if (str_eq(conf->log_file, "")) {
return conf->debug;
}
#ifdef HAVE_SYSLOG
if (str_eq(conf->log_file, "syslog")) {
use_syslog = true;
openlog("ccache", LOG_PID, LOG_USER);
return true;
}
#endif
logfile = fopen(conf->log_file, "a");
if (logfile) {
#ifndef _WIN32
set_cloexec_flag(fileno(logfile));
#endif
return true;
} else {
return false;
}
}
示例11: _internal_get_from_bb_bin_alloc
static bool
_internal_get_from_bb_bin_alloc (xmmsv_t *bb,
unsigned char **buf,
unsigned int *len)
{
unsigned char *b;
int32_t l;
if (!_internal_get_from_bb_int32_positive (bb, &l)) {
return false;
}
b = x_malloc (l);
if (!b) {
return false;
}
if (!_internal_get_from_bb_data (bb, b, l)) {
free (b);
return false;
}
*buf = b;
*len = l;
return true;
}
示例12: save_render_options_inc
void save_render_options_inc (render_struct *rs) {
// Private method, added 2007-01-01
// Save some render options in render_options.inc, in the current directory
// those that are not camera related
// and that cannot be specified on the command line
FILE *fin;
gchar *msg_buf, str_format[100], *ext;
if (!(fin=fopen("render_options.inc","wb"))) {
msg_buf = (gchar *) x_malloc(sizeof(gchar) + strlen("render_options.inc") + strlen(_("Not able to open '%s' file for writing"))+5, "const gchar (msg_buf - open file for writing)");
sprintf(msg_buf,_("Not able to open '%s' file for writing"),"render_options.inc");
my_msg(msg_buf,WARNING);
}
else {
// loc = setlocale(LC_NUMERIC,""); // Povray uses "." as decimal separator instead of ","
// setlocale(LC_NUMERIC,"C");
if (*rs->if_creation || *rs->if_modified) {
// The PNG file to render is written in a temporary directory
fprintf(fin,"#declare hf_to_render = %c%s%c;\n",'\"',HF_OUTPUT_FOR_RENDERING,'\"');
fprintf(fin,"#declare temporary_directory = %c%s%c;\n",'\"',TMP_DIR,'\"');
}
else
// If the current height field has not been changed, we render the source file
fprintf(fin,"#declare hf_to_render = %c%s%c;\n",'\"',*rs->filename,'\"');
fprintf(fin,"#declare current_directory = %c%s%c;\n",'\"',*rs->dirname,'\"');
ext = strstr(*rs->filename,".png");
if (ext) {
sprintf(str_format, "#declare fname_radix = %%c%%%d.%ds%%c;\n", ext-*rs->filename,ext-*rs->filename);
// printf("STR_FORMAT: %s\n",str_format);
fprintf(fin,str_format,'\"',*rs->filename,'\"');
}
// setlocale(LC_NUMERIC,loc);
fclose(fin);
}
}
示例13: stun_set_attr_d
/**
* set attribute of type to malloc'ed value copy of val.
*/
static int
stun_set_attr_d(stun_packet_t *pkt, int atype, int len, char *val)
{
int i;
i = stun_attr_id(pkt, atype);
//TRACE("))))))))))))))))) 2 i=%d, attrnum(%d)\n",i,(int)pkt->attrnum);
if (i < 0)
{
pkt->attrs = x_realloc(pkt->attrs,
sizeof(stun_attr_t) * (pkt->attrnum + 2));
i = pkt->attrnum;
}
//TRACE("))))))))))))))))) 3\n");
pkt->attrs[i].type = (uint16_t) atype;
pkt->attrs[i].len = (uint16_t) len;
if (pkt->attrs[pkt->attrnum].len)
{
// TRACE("))))))))))))))))) 4\n");
pkt->attrs[i].data = x_malloc(pkt->attrs[i].len);
x_memcpy(pkt->attrs[pkt->attrnum].data, val, len);
}
else
pkt->attrs[i].data = NULL;
// end with NULL
pkt->attrs[++pkt->attrnum].type = 0;
// TRACE("))))))))))))))))) 5\n");
return 0;
}
示例14: stun_x_mapped
/**
* returns x-mapped address buffer
*/
static char *
stun_x_mapped(struct sockaddr_in *saddr)
{
uint16_t port;
uint32_t ip;
char *xmapped;
ENTER;
xmapped = (char *) x_memset(x_malloc(8), 0, 8);
xmapped[0] = 0;
xmapped[1] = 1; // ipv4
TRACE("MAPPING %s:%d\n", inet_ntoa(saddr->sin_addr), ntohs(saddr->sin_port));
ip = ntohl(saddr->sin_addr.s_addr);
port = ntohs(saddr->sin_port);
port ^= 0x2112;
ip ^= STUN_M_COOKIE;
port = htons(port);
ip = htonl(ip);
x_memcpy(xmapped + 2, &port, 2);
x_memcpy(xmapped + 4, &ip, 4);
EXIT;
return xmapped;
}
示例15: x_malloc
swirl_struct *swirl_pen_new() {
swirl_struct *s;
s = (swirl_struct *) x_malloc(sizeof(swirl_struct), "swirl_struct");
s->size = 81;
s->angle = 0;
return s;
}