本文整理汇总了C++中ALLOC_N函数的典型用法代码示例。如果您正苦于以下问题:C++ ALLOC_N函数的具体用法?C++ ALLOC_N怎么用?C++ ALLOC_N使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ALLOC_N函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: cont_capture
static VALUE
cont_capture(volatile int *stat)
{
rb_context_t *cont;
rb_thread_t *th = GET_THREAD();
volatile VALUE contval;
THREAD_MUST_BE_RUNNING(th);
rb_vm_stack_to_heap(th);
cont = cont_new(rb_cContinuation);
contval = cont->self;
#ifdef CAPTURE_JUST_VALID_VM_STACK
cont->vm_stack_slen = th->cfp->sp + th->mark_stack_len - th->stack;
cont->vm_stack_clen = th->stack + th->stack_size - (VALUE*)th->cfp;
cont->vm_stack = ALLOC_N(VALUE, cont->vm_stack_slen + cont->vm_stack_clen);
MEMCPY(cont->vm_stack, th->stack, VALUE, cont->vm_stack_slen);
MEMCPY(cont->vm_stack + cont->vm_stack_slen, (VALUE*)th->cfp, VALUE, cont->vm_stack_clen);
#else
cont->vm_stack = ALLOC_N(VALUE, th->stack_size);
MEMCPY(cont->vm_stack, th->stack, VALUE, th->stack_size);
#endif
cont->saved_thread.stack = 0;
cont_save_machine_stack(th, cont);
/* backup ensure_list to array for search in another context */
{
rb_ensure_list_t *p;
int size = 0;
rb_ensure_entry_t *entry;
for (p=th->ensure_list; p; p=p->next)
size++;
entry = cont->ensure_array = ALLOC_N(rb_ensure_entry_t,size+1);
for (p=th->ensure_list; p; p=p->next) {
if (!p->entry.marker)
p->entry.marker = rb_ary_tmp_new(0); /* dummy object */
*entry++ = p->entry;
}
entry->marker = 0;
}
if (ruby_setjmp(cont->jmpbuf)) {
volatile VALUE value;
VAR_INITIALIZED(cont);
value = cont->value;
if (cont->argc == -1) rb_exc_raise(value);
cont->value = Qnil;
*stat = 1;
return value;
}
else {
*stat = 0;
return contval;
}
}
开发者ID:0x00evil,项目名称:ruby,代码行数:57,代码来源:cont.c
示例2: na_make_view
/*
* call-seq:
* narray.view => narray
*
* Return view of NArray
*/
VALUE
na_make_view(VALUE self)
{
int i, nd;
size_t j;
size_t *idx1, *idx2;
ssize_t stride;
narray_t *na;
narray_view_t *na1, *na2;
volatile VALUE view;
GetNArray(self,na);
nd = na->ndim;
view = na_s_allocate_view(CLASS_OF(self));
na_copy_flags(self, view);
GetNArrayView(view, na2);
na_setup_shape((narray_t*)na2, nd, na->shape);
na2->stridx = ALLOC_N(stridx_t,nd);
switch(na->type) {
case NARRAY_DATA_T:
case NARRAY_FILEMAP_T:
stride = na_get_elmsz(self);
for (i=nd; i--;) {
SDX_SET_STRIDE(na2->stridx[i],stride);
stride *= na->shape[i];
}
na2->offset = 0;
na2->data = self;
break;
case NARRAY_VIEW_T:
GetNArrayView(self, na1);
for (i=0; i<nd; i++) {
if (SDX_IS_INDEX(na1->stridx[i])) {
idx1 = SDX_GET_INDEX(na1->stridx[i]);
idx2 = ALLOC_N(size_t,na1->base.shape[i]);
for (j=0; j<na1->base.shape[i]; j++) {
idx2[j] = idx1[j];
}
SDX_SET_INDEX(na2->stridx[i],idx2);
} else {
na2->stridx[i] = na1->stridx[i];
}
}
na2->offset = na1->offset;
na2->data = na1->data;
break;
}
return view;
}
开发者ID:yui-knk,项目名称:narray,代码行数:60,代码来源:narray.c
示例3: redtree_init_struct
void redtree_init_struct(struct redtree* tree) {
tree->tokens = ALLOC_N(redtree_token, INITIAL_TOKEN_COUNT);
tree->token_locations = ALLOC_N(struct token_location, INITIAL_TOKEN_COUNT);
tree->token_size = INITIAL_TOKEN_COUNT;
tree->token_count = 0;
tree->sequence = ALLOC_N(redtree_sequence_entry, INITIAL_SEQUENCE_COUNT);
tree->sequence_size = INITIAL_SEQUENCE_COUNT;
tree->sequence_count = 0;
tree->lines = ALLOC_N(VALUE, INITIAL_LINE_COUNT);
tree->line_size = INITIAL_LINE_COUNT;
tree->line_count = 0;
tree->enc = 0;
}
开发者ID:michaeledgar,项目名称:redtree,代码行数:13,代码来源:tree.c
示例4: cont_save_machine_stack
static void
cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont)
{
size_t size;
rb_thread_t *sth = &cont->saved_thread;
SET_MACHINE_STACK_END(&th->machine_stack_end);
#ifdef __ia64
th->machine_register_stack_end = rb_ia64_bsp();
#endif
if (th->machine_stack_start > th->machine_stack_end) {
size = cont->machine_stack_size = th->machine_stack_start - th->machine_stack_end;
cont->machine_stack_src = th->machine_stack_end;
}
else {
size = cont->machine_stack_size = th->machine_stack_end - th->machine_stack_start;
cont->machine_stack_src = th->machine_stack_start;
}
if (cont->machine_stack) {
REALLOC_N(cont->machine_stack, VALUE, size);
}
else {
cont->machine_stack = ALLOC_N(VALUE, size);
}
FLUSH_REGISTER_WINDOWS;
MEMCPY(cont->machine_stack, cont->machine_stack_src, VALUE, size);
#ifdef __ia64
rb_ia64_flushrs();
size = cont->machine_register_stack_size = th->machine_register_stack_end - th->machine_register_stack_start;
cont->machine_register_stack_src = th->machine_register_stack_start;
if (cont->machine_register_stack) {
REALLOC_N(cont->machine_register_stack, VALUE, size);
}
else {
cont->machine_register_stack = ALLOC_N(VALUE, size);
}
MEMCPY(cont->machine_register_stack, cont->machine_register_stack_src, VALUE, size);
#endif
sth->machine_stack_start = sth->machine_stack_end = 0;
#ifdef __ia64
sth->machine_register_stack_start = sth->machine_register_stack_end = 0;
#endif
}
开发者ID:pascalt,项目名称:captalog,代码行数:49,代码来源:cont.c
示例5: na_expand_dims
/*
* call-seq:
* narray.expand_dims(dim) => narray view
*
* Expand the shape of an array. Insert a new axis with size=1
* at a given dimension.
* @param [Integer] dim dimension at which new axis is inserted.
* @return [Numo::NArray] result narray view.
*/
VALUE
na_expand_dims(VALUE self, VALUE vdim)
{
int i, j, nd, dim;
size_t *shape, *na_shape;
stridx_t *stridx, *na_stridx;
narray_t *na;
narray_view_t *na2;
VALUE view;
GetNArray(self,na);
nd = na->ndim;
dim = NUM2INT(vdim);
if (dim < -nd-1 || dim > nd) {
rb_raise(nary_eDimensionError,"invalid axis (%d for %dD NArray)",
dim,nd);
}
if (dim < 0) {
dim += nd+1;
}
view = na_make_view(self);
GetNArrayView(view, na2);
shape = ALLOC_N(size_t,nd+1);
stridx = ALLOC_N(stridx_t,nd+1);
na_shape = na2->base.shape;
na_stridx = na2->stridx;
for (i=j=0; i<=nd; i++) {
if (i==dim) {
shape[i] = 1;
SDX_SET_STRIDE(stridx[i],0);
} else {
shape[i] = na_shape[j];
stridx[i] = na_stridx[j];
j++;
}
}
na2->stridx = stridx;
xfree(na_stridx);
na2->base.shape = shape;
xfree(na_shape);
na2->base.ndim++;
return view;
}
开发者ID:yui-knk,项目名称:narray,代码行数:57,代码来源:narray.c
示例6: sp_session_create
sp_error
sp_session_create(const sp_session_config *config, sp_session * *sess)
{
sp_session *session;
if (memcmp(config->application_key, "appkey_good", config->application_key_size))
return SP_ERROR_BAD_APPLICATION_KEY;
session = *sess = ALLOC(sp_session);
session->config.api_version = config->api_version;
session->config.cache_location = strclone(config->cache_location);
session->config.settings_location = strclone(config->settings_location);
session->config.user_agent = strclone(config->user_agent);
session->config.callbacks = ALLOC(sp_session_callbacks);
session->config.userdata = config->userdata;
session->config.application_key = ALLOC_N(byte, config->application_key_size);
memcpy((char *) session->config.application_key, config->application_key, config->application_key_size);
if (config->callbacks)
{
MEMCPY((sp_session_callbacks *) session->config.callbacks, config->callbacks, sp_session_callbacks);
}
// sp_session defaults
session->cache_size = 0;
// TODO: v0.0.8 (and earlier) directly call `notify_main_thread` callback here, before returning
if (config->callbacks && config->callbacks->notify_main_thread)
config->callbacks->notify_main_thread(session);
return SP_ERROR_OK;
}
开发者ID:bok,项目名称:libmockspotify,代码行数:34,代码来源:session.c
示例7: fa_compile
/* Construct a finite automaton from REGEXP and return it in *FA.
*
* Return NULL if REGEXP is valid, if the regexp REGEXP has syntax errors,
* return an exception.
*/
static struct value *str_to_fa(struct info *info, const char *pattern,
struct fa **fa) {
int error;
struct value *exn = NULL;
size_t re_err_len;
char *re_str, *re_err;
error = fa_compile(pattern, strlen(pattern), fa);
if (error == REG_NOERROR)
return NULL;
re_str = escape(pattern, -1);
if (re_str == NULL) {
FIXME("Out of memory");
}
exn = make_exn_value(info, "Invalid regular expression /%s/", re_str);
re_err_len = regerror(error, NULL, NULL, 0);
if (ALLOC_N(re_err, re_err_len) < 0) {
FIXME("Out of memory");
}
regerror(error, NULL, re_err, re_err_len);
exn_printf_line(exn, "%s", re_err);
free(re_str);
free(re_err);
return exn;
}
开发者ID:camptocamp,项目名称:augeas,代码行数:33,代码来源:lens.c
示例8: grpc_rb_hash_convert_to_channel_args0
static VALUE grpc_rb_hash_convert_to_channel_args0(VALUE as_value) {
ID id_size = rb_intern("size");
VALUE grpc_rb_cChannelArgs = rb_define_class("TmpChannelArgs", rb_cObject);
channel_convert_params* params = (channel_convert_params*)as_value;
size_t num_args = 0;
if (!NIL_P(params->src_hash) && TYPE(params->src_hash) != T_HASH) {
rb_raise(rb_eTypeError, "bad channel args: got:<%s> want: a hash or nil",
rb_obj_classname(params->src_hash));
return Qnil;
}
if (TYPE(params->src_hash) == T_HASH) {
num_args = NUM2INT(rb_funcall(params->src_hash, id_size, 0));
params->dst->num_args = num_args;
params->dst->args = ALLOC_N(grpc_arg, num_args);
MEMZERO(params->dst->args, grpc_arg, num_args);
rb_hash_foreach(params->src_hash,
grpc_rb_channel_create_in_process_add_args_hash_cb,
Data_Wrap_Struct(grpc_rb_cChannelArgs, GC_NOT_MARKED,
GC_DONT_FREE, params->dst));
/* reset num_args as grpc_rb_channel_create_in_process_add_args_hash_cb
* decrements it during has processing */
params->dst->num_args = num_args;
}
return Qnil;
}
开发者ID:cluo,项目名称:grpc,代码行数:27,代码来源:rb_channel_args.c
示例9: thread_recycle_struct
static rb_thread_t *
thread_recycle_struct(void)
{
void *p = ALLOC_N(rb_thread_t, 1);
memset(p, 0, sizeof(rb_thread_t));
return p;
}
开发者ID:qnighy,项目名称:ruby-1.9.2p0,代码行数:7,代码来源:vm.c
示例10: Buffer_alloc
static VALUE Buffer_alloc(VALUE klass)
{
msgpack_buffer_t* b = ALLOC_N(msgpack_buffer_t, 1);
msgpack_buffer_init(b);
return Data_Wrap_Struct(klass, msgpack_buffer_mark, Buffer_free, b);
}
开发者ID:josephholsten,项目名称:msgpack-ruby,代码行数:7,代码来源:buffer_class.c
示例11: na_parse_narray_index
static void
na_parse_narray_index(VALUE a, int orig_dim, ssize_t size, na_index_arg_t *q)
{
VALUE idx;
narray_t *na;
narray_data_t *nidx;
size_t k, n;
ssize_t *nidxp;
GetNArray(a,na);
if (NA_NDIM(na) != 1) {
rb_raise(rb_eIndexError, "should be 1-d NArray");
}
n = NA_SIZE(na);
idx = nary_new(cIndex,1,&n);
na_store(idx,a);
GetNArrayData(idx,nidx);
nidxp = (ssize_t*)nidx->ptr;
q->idx = ALLOC_N(size_t, n);
for (k=0; k<n; k++) {
q->idx[k] = na_range_check(nidxp[k], size, orig_dim);
}
q->n = n;
q->beg = 0;
q->step = 1;
q->reduce = 0;
q->orig_dim = orig_dim;
}
开发者ID:kou,项目名称:narray,代码行数:29,代码来源:index.c
示例12: sysconf
static char *get_home_dir(uid_t uid) {
char *strbuf;
char *result;
struct passwd pwbuf;
struct passwd *pw = NULL;
long val = sysconf(_SC_GETPW_R_SIZE_MAX);
size_t strbuflen = val;
if (val < 0)
return NULL;
if (ALLOC_N(strbuf, strbuflen) < 0)
return NULL;
if (getpwuid_r(uid, &pwbuf, strbuf, strbuflen, &pw) != 0 || pw == NULL) {
free(strbuf);
return NULL;
}
result = strdup(pw->pw_dir);
free(strbuf);
return result;
}
开发者ID:camptocamp,项目名称:augeas-debian,代码行数:25,代码来源:augtool.c
示例13: cont_capture
static VALUE
cont_capture(volatile int *stat)
{
rb_context_t *cont;
rb_thread_t *th = GET_THREAD(), *sth;
volatile VALUE contval;
vm_stack_to_heap(th);
cont = cont_new(rb_cContinuation);
contval = cont->self;
sth = &cont->saved_thread;
cont->vm_stack = ALLOC_N(VALUE, th->stack_size);
MEMCPY(cont->vm_stack, th->stack, VALUE, th->stack_size);
sth->stack = 0;
cont_save_machine_stack(th, cont);
if (ruby_setjmp(cont->jmpbuf)) {
VALUE value;
value = cont->value;
cont->value = Qnil;
*stat = 1;
return value;
}
else {
*stat = 0;
return cont->self;
}
}
开发者ID:genki,项目名称:ruby,代码行数:31,代码来源:cont.c
示例14: Ashton_PixelCache_init
VALUE Ashton_PixelCache_init(VALUE self, VALUE owner)
{
PIXEL_CACHE();
pixel_cache->rb_owner = owner;
// Different behaviour depending on what the owning class is.
if(RTEST(rb_obj_is_kind_of(owner, rb_cTexture)))
{
// Ashton::Texture
pixel_cache->texture_id = NUM2UINT(rb_funcall(owner, rb_intern("id"), 0));
}
else if(RTEST(rb_obj_is_kind_of(owner, rb_cImage)))
{
// Gosu::Image
// TODO: this needs to be done completely differently, since the image is a sprite on a texture, 1024x1024.
VALUE tex_info = rb_funcall(owner, rb_intern("gl_tex_info"), 0);
pixel_cache->texture_id = NUM2UINT(rb_funcall(tex_info, rb_intern("tex_name"), 0));
}
else
{
rb_raise(rb_eTypeError, "Can only cache Gosu::Image or Ashton::Texture objects.");
}
pixel_cache->width = NUM2UINT(rb_funcall(owner, rb_intern("width"), 0));
pixel_cache->height = NUM2UINT(rb_funcall(owner, rb_intern("height"), 0));
pixel_cache->data = ALLOC_N(Color_i, pixel_cache->width * pixel_cache->height);
cache_texture(pixel_cache);
return Qnil;
}
开发者ID:KajiMaster,项目名称:ashton,代码行数:31,代码来源:pixel_cache.c
示例15: ifact_create_items
static VALUE
ifact_create_items(VALUE self, VALUE ary)
{
VALUE entry, path, accel, type, func, data, extdata;
GtkItemFactoryEntry *entries;
guint i, len, n_menu_entries;
n_menu_entries = RARRAY_LEN(ary);
entries = ALLOC_N(GtkItemFactoryEntry, n_menu_entries);
for (i = 0; i < n_menu_entries; i++) {
entry = RARRAY_PTR(ary)[i];
len = RARRAY_LEN(entry);
Check_Type(entry, T_ARRAY);
path = RARRAY_PTR(entry)[0];
type = ((len > 1) ? RARRAY_PTR(entry)[1] : Qnil);
accel = ((len > 2) ? RARRAY_PTR(entry)[2] : Qnil);
extdata = ((len > 3) ? RARRAY_PTR(entry)[3] : Qnil);
func = ((len > 4) ? RARRAY_PTR(entry)[4] : Qnil);
data = ((len > 5) ? RARRAY_PTR(entry)[5] : Qnil);
create_factory_entry(&entries[i], self, path, type, accel, extdata, func, data);
}
gtk_item_factory_create_items (_SELF(self), n_menu_entries, entries, NULL);
g_free(entries);
return self;
}
开发者ID:benolee,项目名称:ruby-gnome2,代码行数:29,代码来源:rbgtkitemfactory.c
示例16: pp_leds_allocate
static VALUE
pp_leds_allocate( VALUE klass )
{
int ii;
ws2811_t *ledstring;
ledstring = ALLOC_N( ws2811_t, 1 );
if (!ledstring) {
rb_raise(rb_eNoMemError, "could not allocate PixelPi::Leds instance");
}
ledstring->freq = WS2811_TARGET_FREQ;
ledstring->dmanum = 5;
ledstring->device = NULL;
for (ii=0; ii<RPI_PWM_CHANNELS; ii++) {
ledstring->channel[ii].gpionum = 0;
ledstring->channel[ii].count = 0;
ledstring->channel[ii].invert = 0;
ledstring->channel[ii].brightness = 255;
ledstring->channel[ii].leds = NULL;
}
return Data_Wrap_Struct( klass, NULL, pp_leds_free, ledstring );
}
开发者ID:TwP,项目名称:pixel_pi,代码行数:25,代码来源:leds.c
示例17: sp_mock_playlistcontainer_insert
static sp_error
sp_mock_playlistcontainer_insert(sp_playlistcontainer *pc, int index, sp_playlistcontainer_playlist_t playlist)
{
sp_playlistcontainer_playlist_t *new_playlists;
int num_playlists = sp_playlistcontainer_num_playlists(pc);
int new_num_playlists = num_playlists + 1;
int i, j;
if (index > num_playlists || index < 0)
{
return SP_ERROR_INDEX_OUT_OF_RANGE;
}
new_playlists = ALLOC_N(sp_playlistcontainer_playlist_t, new_num_playlists);
for (i = 0, j = 0; i < new_num_playlists; i++)
{
if (i == index)
{
MEMCPY(&new_playlists[i], &playlist, sp_playlistcontainer_playlist_t);
}
else
{
MEMCPY(&new_playlists[i], &pc->playlists[j++], sp_playlistcontainer_playlist_t);
}
}
free(pc->playlists);
pc->playlists = new_playlists;
pc->num_playlists = new_num_playlists;
return SP_ERROR_OK;
}
开发者ID:Burgestrand,项目名称:libmockspotify,代码行数:32,代码来源:playlistcontainer.c
示例18: sp_playlistcontainer_remove_playlist
sp_error
sp_playlistcontainer_remove_playlist(sp_playlistcontainer *pc, int index)
{
sp_playlistcontainer_playlist_t *new_playlists;
int num_playlists = sp_playlistcontainer_num_playlists(pc);
int new_num_playlists = num_playlists - 1;
int i, j;
if (index >= num_playlists || index < 0)
{
return SP_ERROR_INDEX_OUT_OF_RANGE;
}
new_playlists = ALLOC_N(sp_playlistcontainer_playlist_t, new_num_playlists);
for (i = 0, j = 0; i < num_playlists; ++i)
{
if (i != index)
{
MEMCPY(&new_playlists[j++], &pc->playlists[i], sp_playlistcontainer_playlist_t);
}
}
free(pc->playlists);
pc->playlists = new_playlists;
pc->num_playlists = new_num_playlists;
return SP_ERROR_OK;
}
开发者ID:Burgestrand,项目名称:libmockspotify,代码行数:28,代码来源:playlistcontainer.c
示例19: rf_extend_if_necessary
static void rf_extend_if_necessary(RAMFile *rf, int buf_num)
{
while (rf->bufcnt <= buf_num) {
REALLOC_N(rf->buffers, uchar *, (rf->bufcnt + 1));
rf->buffers[rf->bufcnt++] = ALLOC_N(uchar, BUFFER_SIZE);
}
}
开发者ID:Bira,项目名称:ferret,代码行数:7,代码来源:ram_store.c
示例20: run_args
static int run_args(int argc, char **argv) {
size_t len = 0;
char *line = NULL;
int code;
for (int i=0; i < argc; i++)
len += strlen(argv[i]) + 1;
if (ALLOC_N(line, len + 1) < 0)
return -1;
for (int i=0; i < argc; i++) {
strcat(line, argv[i]);
strcat(line, " ");
}
if (echo_commands)
printf("%s%s\n", AUGTOOL_PROMPT, line);
code = run_command(line);
free(line);
if (code >= 0 && auto_save)
if (echo_commands)
printf("%ssave\n", AUGTOOL_PROMPT);
code = run_command("save");
if (code < 0) {
code = -1;
print_aug_error();
}
return (code >= 0 || code == -2) ? 0 : -1;
}
开发者ID:camptocamp,项目名称:augeas-debian,代码行数:28,代码来源:augtool.c
注:本文中的ALLOC_N函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论