本文整理汇总了C++中cmalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ cmalloc函数的具体用法?C++ cmalloc怎么用?C++ cmalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cmalloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: move_layer_block
static void move_layer_block(
char *src_char, char *src_color, int src_width, int src_offset,
char *dest_char, char *dest_color, int dest_width, int dest_offset,
int block_width, int block_height,
int clear_width, int clear_height)
{
// Similar to copy_layer_to_layer_buffered, but deletes the source
// after copying to the buffer.
char *buffer_char = cmalloc(block_width * block_height);
char *buffer_color = cmalloc(block_width * block_height);
// Copy source to buffer
copy_layer_buffer_to_buffer(
src_char, src_color, src_width, src_offset,
buffer_char, buffer_color, block_width, 0,
block_width, block_height);
// Clear the source
clear_layer_block(
src_char, src_color, src_width, src_offset,
clear_width, clear_height);
// Copy buffer to destination
copy_layer_buffer_to_buffer(
buffer_char, buffer_color, block_width, 0,
dest_char, dest_color, dest_width, dest_offset,
block_width, block_height);
free(buffer_char);
free(buffer_color);
}
开发者ID:AliceLR,项目名称:megazeux,代码行数:32,代码来源:block.c
示例2: comm_pseudo
void comm_pseudo(PSEUDO *pseudo,MPI_Comm world,int myid)
/*=======================================================================*/
/* Begin routine */
{/*begin routine */
/*=======================================================================*/
/* Local variable declarations */
#include "../typ_defs/typ_mask.h"
if(myid!=0){
pseudo->vxc_typ = (char *)cmalloc(MAXWORD*sizeof(char));
pseudo->ggax_typ = (char *)cmalloc(MAXWORD*sizeof(char));
pseudo->ggac_typ = (char *)cmalloc(MAXWORD*sizeof(char));
}/*endif*/
Barrier(world);
Bcast(&(pseudo->vxc_typ[0]),MAXWORD,MPI_CHAR,0,world); /* must be from 0*/
Bcast(&(pseudo->ggax_typ[0]),MAXWORD,MPI_CHAR,0,world);
Bcast(&(pseudo->ggac_typ[0]),MAXWORD,MPI_CHAR,0,world);
Bcast(&(pseudo->gga_cut),1,MPI_DOUBLE,0,world);
Bcast(&(pseudo->b3_cut),1,MPI_DOUBLE,0,world);
Bcast(&(pseudo->b3_alp),1,MPI_DOUBLE,0,world);
Bcast(&(pseudo->alpha_conv_dual),1,MPI_DOUBLE,0,world);
Bcast(&(pseudo->n_interp_pme_dual),1,MPI_INT,0,world);
Bcast(&(pseudo->nsplin_g),1,MPI_INT,0,world);
Bcast(&(pseudo->nl_cut_on),1,MPI_INT,0,world);
Bcast(&(pseudo->nlvps_skin),1,MPI_DOUBLE,0,world);
Barrier(world);
/*------------------------------------------------------------------------*/
} /*end routine*/
开发者ID:mingchenaabb,项目名称:PINY-XLBOMD,代码行数:33,代码来源:comm_cp_data.c
示例3: newgroup
void newgroup(FILE *output, char *group_name, char **description, int words) {
group *g;
char *dstring;
int i, len = 0;
if (group_name && words > 0) {
g = get_group(group_name);
if (g != NULL && ! prohibited_group_p(g)) {
fprintf(output, "Group %s already exists\n.\n", group_name);
return;
}
for (i = 0; i < words; i++)
len += strlen(description[i]) + 1;
dstring = cmalloc(len);
for (i = 0; i < words; i++) {
if (i > 0)
strcat(dstring, " ");
strcat(dstring, description[i]);
}
g->group_description = enter_string_storage(dstring);
alphabetize_groups();
free(dstring);
fprintf(output, "Created group %s\n.\n", group_name);
} else {
fprintf(output, "Not creating group %s\n.\n", group_name);
}
}
开发者ID:ebcode,项目名称:weaverd,代码行数:33,代码来源:hash.c
示例4: font_box_put_item
static void font_box_put_item (
char **item, /* Pointer to the pointer to the */
/* item to insert (C is great) */
/* RETURNED */
int *number, /* Pointer to the number of items */
/* RETURNED */
char ***menu_list) /* Pointer to the pointer to the */
/* array of items (C is $%*[email protected]#) */
{
int i, j;
/* Do nothing if the item is undefined */
if (NULL == *item) return;
/* Search an item equal to the one to insert in the list */
for (i = 0; (i < *number) && (strcmp ((*menu_list) [i], *item)); i++);
/* If found, modify the pointer to the item */
if (i < *number) {
eif_rt_xfree (*item);
*item = (*menu_list) [i];
return;
}
/* If not insert it into the list */
if ((*number)++) *menu_list = (char **) crealloc (*menu_list, (*number)*sizeof (char *));
else *menu_list = (char **) cmalloc (sizeof (char *));
(*menu_list) [i] = *item;
}
开发者ID:jocelyn,项目名称:EiffelStudio,代码行数:29,代码来源:font_box.c
示例5: load_mzm
int load_mzm(struct world *mzx_world, char *name, int start_x, int start_y,
int mode, int savegame)
{
FILE *input_file;
size_t file_size;
void *buffer;
int success;
input_file = fopen_unsafe(name, "rb");
if(input_file)
{
fseek(input_file, 0, SEEK_END);
file_size = ftell(input_file);
buffer = cmalloc(file_size);
fseek(input_file, 0, SEEK_SET);
fread(buffer, file_size, 1, input_file);
fclose(input_file);
success = load_mzm_common(mzx_world, buffer, (int)file_size, start_x, start_y, mode, savegame, name);
free(buffer);
return success;
} else {
error_message(E_MZM_DOES_NOT_EXIST, 0, name);
return -1;
}
}
开发者ID:colin-branch,项目名称:megazeux,代码行数:25,代码来源:mzm.c
示例6: swivel_current_dir
static bool swivel_current_dir(bool have_video)
{
bool ret = false;
char *base_path;
int g_ret;
// Store the user's current directory, so we can get back to it
getcwd(previous_dir, MAX_PATH);
base_path = cmalloc(MAX_PATH);
// Find and change into the base path for this MZX binary
g_ret = get_path(process_argv[0], base_path, MAX_PATH);
if(g_ret <= 0)
goto err_free_base_path;
if(chdir(base_path))
{
if(have_video)
error("Failed to change into install directory.", 1, 8, 0);
else
warn("Failed to change into install directory.\n");
goto err_free_base_path;
}
ret = true;
err_free_base_path:
free(base_path);
return ret;
}
开发者ID:colin-branch,项目名称:megazeux,代码行数:30,代码来源:updater.c
示例7: init_node_table
void init_node_table(void) {
node_table = (int*)cmalloc(node_table_length * sizeof(int));
#ifdef USAGE
printf("Allocating %dM for node hash table\n",
meg(node_table_length * sizeof(int)));
#endif
}
开发者ID:ebcode,项目名称:weaverd,代码行数:7,代码来源:hash.c
示例8: help_open
void help_open(struct world *mzx_world, const char *file_name)
{
mzx_world->help_file = fopen_unsafe(file_name, "rb");
if(!mzx_world->help_file)
return;
help = cmalloc(1024 * 64);
}
开发者ID:MrAlert,项目名称:megazeux,代码行数:8,代码来源:helpsys.c
示例9:
void
·_Cfunc_CString(String s, int8 *p)
{
p = runtime·cmalloc(s.len+1);
runtime·memmove((byte*)p, s.str, s.len);
p[s.len] = 0;
FLUSH(&p);
}
开发者ID:golang-basic,项目名称:gobasic,代码行数:8,代码来源:_cgo_defun.c
示例10: add_rule
int add_rule(char *s, char *t, char *c, char *p, policydb_t *policy) {
type_datum_t *src, *tgt;
class_datum_t *cls;
perm_datum_t *perm;
avtab_datum_t *av;
avtab_key_t key;
src = hashtab_search(policy->p_types.table, s);
if (src == NULL) {
fprintf(stderr, "source type %s does not exist\n", s);
return 2;
}
tgt = hashtab_search(policy->p_types.table, t);
if (tgt == NULL) {
fprintf(stderr, "target type %s does not exist\n", t);
return 2;
}
cls = hashtab_search(policy->p_classes.table, c);
if (cls == NULL) {
fprintf(stderr, "class %s does not exist\n", c);
return 2;
}
perm = hashtab_search(cls->permissions.table, p);
if (perm == NULL) {
if (cls->comdatum == NULL) {
fprintf(stderr, "perm %s does not exist in class %s\n", p, c);
return 2;
}
perm = hashtab_search(cls->comdatum->permissions.table, p);
if (perm == NULL) {
fprintf(stderr, "perm %s does not exist in class %s\n", p, c);
return 2;
}
}
// See if there is already a rule
key.source_type = src->s.value;
key.target_type = tgt->s.value;
key.target_class = cls->s.value;
key.specified = AVTAB_ALLOWED;
av = avtab_search(&policy->te_avtab, &key);
if (av == NULL) {
int ret;
av = cmalloc(sizeof av);
av->data |= 1U << (perm->s.value - 1);
ret = avtab_insert(&policy->te_avtab, &key, av);
if (ret) {
fprintf(stderr, "Error inserting into avtab\n");
return 1;
}
}
av->data |= 1U << (perm->s.value - 1);
return 0;
}
开发者ID:Yannik,项目名称:tobias-waldvogel-bootimg-tools,代码行数:58,代码来源:seinject.c
示例11: cmalloc
static struct manifest_entry *manifest_entry_copy(struct manifest_entry *src)
{
struct manifest_entry *dest;
size_t name_len;
dest = cmalloc(sizeof(struct manifest_entry));
name_len = strlen(src->name);
dest->name = cmalloc(name_len + 1);
strncpy(dest->name, src->name, name_len);
dest->name[name_len] = 0;
memcpy(dest->sha256, src->sha256, sizeof(Uint32) * 8);
dest->size = src->size;
dest->next = NULL;
return dest;
}
开发者ID:MrAlert,项目名称:megazeux,代码行数:18,代码来源:manifest.c
示例12: font_box_fill_menu
void font_box_fill_menu (Widget **menu_buttons, Widget menu, int *number, char ***menu_list)
{
int i;
*menu_buttons = (Widget *) cmalloc ((*number)*sizeof (Widget));
for (i = 0; i < *number; i++) {
(*menu_buttons) [i] = XmCreatePushButtonGadget (menu, (*menu_list) [i], NULL, 0);
XtManageChild ((*menu_buttons) [i]);
}
}
开发者ID:jocelyn,项目名称:EiffelStudio,代码行数:10,代码来源:font_box.c
示例13: send_string
/* Send count characters directly to the command.
*/
void send_string(unsigned char* buf, int count)
{
unsigned char* s;
register unsigned char* s1, *s2;
register int i;
if (count == 0)
{
return;
}
if (send_count == 0)
{
if (send_buf != NULL)
{
free(send_buf);
send_buf = NULL;
}
send_buf = (unsigned char*)cmalloc(count);
s2 = send_buf;
s1 = buf;
for (i = 0; i < count; i++, s1++, s2++)
{
*s2 = *s1;
}
send_nxt = send_buf;
send_count = count;
}
else
{
s = (unsigned char*)cmalloc(send_count + count);
memcpy(s, send_nxt, send_count);
s2 = s + send_count;
s1 = buf;
for (i = 0; i < count; i++, s1++, s2++)
{
*s2 = *s1;
}
free(send_buf);
send_buf = send_nxt = s;
send_count += count;
}
}
开发者ID:paulmadore,项目名称:luckyde,代码行数:45,代码来源:command.c
示例14: fopen_unsafe
struct audio_stream *construct_mikmod_stream(char *filename, Uint32 frequency,
Uint32 volume, Uint32 repeat)
{
FILE *input_file;
char *input_buffer;
Uint32 file_size;
struct audio_stream *ret_val = NULL;
input_file = fopen_unsafe(filename, "rb");
if(input_file)
{
MODULE *open_file;
file_size = ftell_and_rewind(input_file);
input_buffer = cmalloc(file_size);
fread(input_buffer, file_size, 1, input_file);
open_file = MikMod_LoadSongRW(SDL_RWFromMem(input_buffer, file_size), 64);
if(open_file)
{
struct mikmod_stream *mm_stream = cmalloc(sizeof(struct mikmod_stream));
mm_stream->module_data = open_file;
Player_Start(mm_stream->module_data);
initialize_sampled_stream((struct sampled_stream *)mm_stream,
mm_set_frequency, mm_get_frequency, frequency, 2, 0);
ret_val = (struct audio_stream *)mm_stream;
construct_audio_stream((struct audio_stream *)mm_stream,
mm_mix_data, mm_set_volume, mm_set_repeat, mm_set_order,
mm_set_position, mm_get_order, mm_get_position, mm_destruct,
volume, repeat);
}
fclose(input_file);
free(input_buffer);
}
return ret_val;
}
开发者ID:MrAlert,项目名称:megazeux,代码行数:43,代码来源:audio_mikmod.c
示例15: extend_string_storage
void extend_string_storage(void) {
size_t new_length = string_storage_length * 2;
char *new_string_storage = cmalloc(new_length);
printf("Extending string storage from %dM to %dM\n",
meg(string_storage_length), meg(new_length));
memcpy(new_string_storage, string_storage, string_storage_length);
crfree(string_storage, string_storage_length);
string_storage = new_string_storage;
string_storage_length = new_length;
}
开发者ID:ebcode,项目名称:weaverd,代码行数:11,代码来源:hash.c
示例16: inserer_symbole
void inserer_symbole(char *nom, int val, char *str, int ch)
{
//printf("inserer_symbole(%s, %d, %s, %d)\n", nom, val, str, ch);
/*printf("avant\n");
print_table_symboles();*/
liste_symboles *aux = table_symboles;
if (aux != NULL) {
while (aux->suivant != NULL) {
aux = aux->suivant;
}
aux->suivant = (liste_symboles *)cmalloc(sizeof(liste_symboles));
aux = aux->suivant;
aux->nom = strdup(nom);
if (ch) {
aux->val_chaine = strdup(str);
} else {
aux->valeur = val;
aux->val_chaine = strdup("");
}
aux->chaine = ch;
aux->suivant = NULL;
} else {
table_symboles = (liste_symboles *)cmalloc(sizeof(liste_symboles));
table_symboles->nom = strdup(nom);
if (ch) {
table_symboles->val_chaine = strdup(str);
} else {
table_symboles->valeur = val;
table_symboles->val_chaine = strdup("");
}
table_symboles->chaine = ch;
table_symboles->suivant = NULL;
}
/*printf("après\n");
print_table_symboles();*/
}
开发者ID:TacOS-team,项目名称:tacos,代码行数:39,代码来源:table_symboles.c
示例17: set_fallback_res
void set_fallback_res (EIF_POINTER w, EIF_OBJ res, EIF_INTEGER count)
{
int counter = 0;
if (fallback_list != (String *) 0) {
String * temp = fallback_list;
while (temp) eif_rt_xfree (*(temp++));
eif_rt_xfree (fallback_list);
fallback_list = (String *) 0;
}
if (res != (EIF_OBJ) 0) {
fallback_list = (String *) cmalloc (count * sizeof (String) + 1);
while (count > counter) {
*(fallback_list + counter) = (String) cmalloc (strlen (*((char **)eif_access(res) + counter)) + 1);
strcpy (*(fallback_list + counter), *((char **)(eif_access (res)) + counter));
counter++;
}
*(fallback_list + counter) = (String) 0;
}
XtAppSetFallbackResources ((XtAppContext) w, fallback_list);
}
开发者ID:jocelyn,项目名称:EiffelStudio,代码行数:22,代码来源:xt_support.c
示例18: title_screen
void title_screen(context *parent)
{
struct config_info *conf = get_config();
struct game_context *title;
struct context_spec spec;
if(edit_world)
{
conf->standalone_mode = false;
}
if(conf->standalone_mode && conf->no_titlescreen)
{
struct game_context dummy;
dummy.ctx.world = parent->world;
if(load_world_gameplay(&dummy, curr_file))
{
play_game(parent, NULL);
return;
}
conf->standalone_mode = false;
}
title = cmalloc(sizeof(struct game_context));
title->fade_in = true;
title->need_reload = true;
title->load_dialog_on_failed_load = true;
title->is_title = true;
memset(&spec, 0, sizeof(struct context_spec));
spec.resume = title_resume;
spec.draw = game_draw;
spec.idle = game_idle;
spec.key = title_key;
spec.joystick = title_joystick;
spec.destroy = game_destroy;
create_context((context *)title, parent, &spec, CTX_TITLE_SCREEN);
default_palette();
if(edit_world && conf->startup_editor)
{
title->load_dialog_on_failed_load = false;
edit_world((context *)title, true);
}
clear_screen();
}
开发者ID:AliceLR,项目名称:megazeux,代码行数:50,代码来源:game.c
示例19: thread_init
int thread_init(int num)
{
if (cmalloc((void**)&wet, (sizeof(WRITE_EV_THREAD) + num * sizeof(WEVENT_T))) < 0 || wet == NULL) {
error(EXIT_FAILURE, errno, "not enough memory\n");
return -1;
}
// wet = (WRITE_EV_THREAD*)cmalloc(sizeof(WRITE_EV_THREAD) + num * sizeof(WEVENT_T));
wet->base = event_init();
wet->evno = num;
wet->st = STAT_READ_MORE;
memset(&wet->ev, 0, num * sizeof(WEVENT_T));
create_stream(&wet->stream, 4096 * 1024);
wet->stream.fd = STDIN_FILENO;
// ret = (READ_EV_THREAD*)cmalloc(sizeof(READ_EV_THREAD) + num * sizeof(struct fdev_t));
if (cmalloc((void**)&ret, (sizeof(READ_EV_THREAD) + num * sizeof(struct fdev_t))) < 0 || ret == NULL) {
error(EXIT_FAILURE, errno, "not enough memory\n");
return -1;
}
ret->base = event_init();
ret->evno = num;
return 0;
}
开发者ID:zhyg,项目名称:mapred,代码行数:23,代码来源:thread.c
示例20: add_change_state
/********************************************************************************
* Specifies when the automata should change the state. If the automata is in
* state "from_state" and reads the word "keyword" it changes to state "to_state"
********************************************************************************/
void add_change_state(int from_state, char *keyword, int to_state) {
struct s_change *change;
change = &change_head;
while(change->next != NULL)
change = change->next;
change->next = cmalloc(sizeof(struct s_change));
change = change->next;
change->from_state = from_state;
change->keyword = keyword;
change->to_state = to_state;
change->next = NULL;
}
开发者ID:BackupTheBerlios,项目名称:vermont-svn,代码行数:18,代码来源:automata.c
注:本文中的cmalloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论