本文整理汇总了C++中SLmalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ SLmalloc函数的具体用法?C++ SLmalloc怎么用?C++ SLmalloc使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SLmalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SLMEMSET
SLcurses_Window_Type *SLcurses_newwin (unsigned int nrows, unsigned int ncols,
unsigned int r, unsigned int c)
{
SLcurses_Window_Type *win;
SLcurses_Cell_Type **lines;
if (r >= (unsigned int) SLtt_Screen_Rows)
return NULL;
if (c >= (unsigned int) SLtt_Screen_Cols)
return NULL;
if (NULL == (win = (SLcurses_Window_Type *) SLmalloc (sizeof (SLcurses_Window_Type))))
return NULL;
SLMEMSET ((char *) win, 0, sizeof (SLcurses_Window_Type));
if (nrows == 0)
nrows = (unsigned int) SLtt_Screen_Rows - r;
if (ncols == 0)
ncols = (unsigned int) SLtt_Screen_Cols - c;
lines = (SLcurses_Cell_Type **) SLmalloc (nrows * sizeof (SLcurses_Cell_Type *));
if (lines == NULL)
{
SLcurses_delwin (win);
return NULL;
}
SLMEMSET ((char *) lines, 0, nrows * sizeof (SLcurses_Cell_Type *));
win->lines = lines;
win->scroll_max = win->nrows = nrows;
win->ncols = ncols;
win->_begy = r;
win->_begx = c;
win->_maxx = (c + ncols) - 1;
win->_maxy = (r + nrows) - 1;
win->modified = 1;
win->delay_off = -1;
for (r = 0; r < nrows; r++)
{
SLcurses_Cell_Type *b;
b = (SLcurses_Cell_Type *) SLmalloc (ncols * sizeof (SLcurses_Cell_Type));
if (b == NULL)
{
SLcurses_delwin (win);
return NULL;
}
lines [r] = b;
blank_line (b, ncols, 0);
}
return win;
}
示例2: SLmalloc
SLcurses_Window_Type *SLcurses_subwin (SLcurses_Window_Type *orig,
unsigned int nlines, unsigned int ncols,
unsigned int begin_y, unsigned int begin_x)
{
SLcurses_Window_Type *sw;
int r, c;
unsigned int i;
if (orig == NULL)
return NULL;
sw = (SLcurses_Window_Type *) SLmalloc (sizeof (SLcurses_Window_Type));
if (sw == NULL)
return NULL;
SLMEMSET ((char *)sw, 0, sizeof (SLcurses_Window_Type));
#if 1
r = begin_y - orig->_begy;
#else
r = 1 + ((int)orig->nrows - (int)nlines) / 2;
#endif
if (r < 0) r = 0;
if (r + nlines > orig->nrows) nlines = orig->nrows - r;
c = ((int)orig->ncols - (int)ncols) / 2;
if (c < 0) c = 0;
if (c + ncols > orig->ncols) ncols = orig->ncols - c;
sw->scroll_min = 0;
sw->scroll_max = sw->nrows = nlines;
sw->ncols = ncols;
sw->_begy = begin_y;
sw->_begx = begin_x;
sw->_maxx = (begin_x + ncols) - 1;
sw->_maxy = (begin_y + nlines) - 1;
sw->lines = (SLcurses_Cell_Type **) SLmalloc (nlines * sizeof (SLcurses_Cell_Type *));
if (sw->lines == NULL)
{
SLcurses_delwin (sw);
return NULL;
}
for (i = 0; i < nlines; i++)
{
sw->lines [i] = orig->lines [r + i] + c;
}
sw->is_subwin = 1;
return sw;
}
示例3: init_smg
static int init_smg (void)
{
unsigned int i, len;
SLsmg_Char_Type *old, *neew;
Smg_Inited = 0;
#ifdef REQUIRES_NON_BCE_SUPPORT
Bce_Color_Offset = _pSLtt_get_bce_color_offset ();
#endif
Screen_Rows = *tt_Screen_Rows;
if (Screen_Rows > SLTT_MAX_SCREEN_ROWS)
Screen_Rows = SLTT_MAX_SCREEN_ROWS;
Screen_Cols = *tt_Screen_Cols;
This_Col = This_Row = Start_Col = Start_Row = 0;
This_Alt_Char = 0;
SLsmg_set_color (0);
Cls_Flag = 1;
init_acs (ACS_MODE_AUTO);
len = Screen_Cols + 3;
for (i = 0; i < Screen_Rows; i++)
{
if ((NULL == (old = (SLsmg_Char_Type *) SLmalloc (sizeof(SLsmg_Char_Type) * len)))
|| ((NULL == (neew = (SLsmg_Char_Type *) SLmalloc (sizeof(SLsmg_Char_Type) * len)))))
{
SLfree ((char *) old);
return -1;
}
blank_line (old, len, ' ');
blank_line (neew, len, ' ');
SL_Screen[i].old = old;
SL_Screen[i].neew = neew;
SL_Screen[i].flags = 0;
#ifndef IBMPC_SYSTEM
Blank_Hash = compute_hash (old, Screen_Cols);
SL_Screen[i].new_hash = SL_Screen[i].old_hash = Blank_Hash;
#endif
}
_pSLtt_color_changed_hook = SLsmg_touch_screen;
Screen_Trashed = 1;
Smg_Inited = 1;
return 0;
}
示例4: SLcalloc
static Host_Addr_Info_Type *alloc_host_addr_info (unsigned int num, int h_length)
{
Host_Addr_Info_Type *hinfo;
size_t nbytes;
char *buf;
unsigned int i;
hinfo = (Host_Addr_Info_Type *) SLcalloc (1, sizeof (Host_Addr_Info_Type));
if (hinfo == NULL)
return NULL;
/* We need memory to hold num (char *) addresses + num*h_length bytes */
nbytes = num * sizeof(char *) + num * h_length;
if (NULL == (buf = (char *)SLmalloc (nbytes)))
{
SLfree ((char *)hinfo);
return NULL;
}
hinfo->h_addr_list = (char **)buf;
buf += num*sizeof(char *);
for (i = 0; i < num; i++)
{
hinfo->h_addr_list[i] = buf;
buf += h_length;
}
hinfo->num = num;
hinfo->h_length = h_length;
return hinfo;
}
示例5: create_undo_ring
void create_undo_ring() /*{{{*/
{
Undo_Type *ur;
Undo_Object_Type *uo;
int n;
if (NULL == (ur = (Undo_Type *) SLmalloc (sizeof(Undo_Type))))
{
msg_error("Unable to malloc space for undo!");
return;
}
CBuf->undo = ur;
uo = ur->Undo_Ring;
ur->Last_Undo = ur->First_Undo = uo;
#ifdef UNDO_HAS_REDO
ur->Current_Undo = NULL;
#endif
n = MAX_UNDOS;
while (n--)
{
uo->type = 0;
uo++;
}
}
示例6: memset
SLFile_FD_Type *SLfile_create_fd (SLFUTURE_CONST char *name, int fd)
{
SLFile_FD_Type *f;
if (name == NULL)
name = "";
if (NULL == (f = (SLFile_FD_Type *) SLmalloc (sizeof (SLFile_FD_Type))))
return NULL;
memset ((char *) f, 0, sizeof (SLFile_FD_Type));
if (NULL == (f->name = SLang_create_slstring (name)))
{
SLfree ((char *)f);
return NULL;
}
f->fd = fd;
f->num_refs = 1;
f->clientdata_id = 0;
f->clientdata = NULL;
/* If NULL, use the standard routines on a file descriptor */
f->close = NULL;
f->read = NULL;
f->write = NULL;
chain_fd_type (f);
return f;
}
示例7: cl_foreach_open
static SLang_Foreach_Context_Type *
cl_foreach_open (SLtype type, unsigned int num)
{
SLang_Foreach_Context_Type *c;
unsigned char flags;
SLang_MMT_Type *mmt;
(void) type;
if (NULL == (mmt = SLang_pop_mmt (SLANG_ASSOC_TYPE)))
return NULL;
flags = 0;
while (num--)
{
char *s;
if (-1 == SLang_pop_slstring (&s))
{
SLang_free_mmt (mmt);
return NULL;
}
if (0 == strcmp (s, "keys"))
flags |= CTX_WRITE_KEYS;
else if (0 == strcmp (s, "values"))
flags |= CTX_WRITE_VALUES;
else
{
_pSLang_verror (SL_NOT_IMPLEMENTED,
"using '%s' not supported by SLassoc_Type",
s);
_pSLang_free_slstring (s);
SLang_free_mmt (mmt);
return NULL;
}
_pSLang_free_slstring (s);
}
if (NULL == (c = (SLang_Foreach_Context_Type *) SLmalloc (sizeof (SLang_Foreach_Context_Type))))
{
SLang_free_mmt (mmt);
return NULL;
}
memset ((char *) c, 0, sizeof (SLang_Foreach_Context_Type));
if (flags == 0) flags = CTX_WRITE_VALUES|CTX_WRITE_KEYS;
c->flags = flags;
c->mmt = mmt;
c->a = (SLang_Assoc_Array_Type *) SLang_object_from_mmt (mmt);
#if SLANG_OPTIMIZE_FOR_SPEED
c->is_scalar = (SLANG_CLASS_TYPE_SCALAR == _pSLang_get_class_type (c->a->type));
#endif
return c;
}
示例8: sprintf
SLang_NameSpace_Type *_SLns_allocate_namespace (char *name, unsigned int size)
{
SLang_NameSpace_Type *table_list;
SLang_Name_Type **nt;
static int num;
char namebuf[64];
if (name == NULL)
{
sprintf (namebuf, " *** internal ns <%d> *** ", num);
name = namebuf;
num++;
}
if (NULL != (table_list = find_name_table (name)))
return table_list;
if (NULL == (name = SLang_create_slstring (name)))
return NULL;
if (NULL == (table_list = (SLang_NameSpace_Type *)
SLmalloc (sizeof (SLang_NameSpace_Type))))
{
SLang_free_slstring (name);
return NULL;
}
if (NULL == (nt = (SLang_Name_Type **) SLmalloc (sizeof (SLang_Name_Type *) * size)))
{
SLang_free_slstring (name);
SLfree ((char *)table_list);
return NULL;
}
memset ((char *)nt, 0, size * sizeof (SLang_Name_Type *));
memset ((char *) table_list, 0, sizeof (SLang_NameSpace_Type));
table_list->name = name;
table_list->table = nt;
table_list->table_size = size;
table_list->next = Namespace_Tables;
Namespace_Tables = table_list;
return table_list;
}
示例9: sizeof
static SLang_BString_Type *create_bstring_of_type (char *bytes, unsigned int len, int type)
{
SLang_BString_Type *b;
unsigned int size;
unsigned int malloced_len = len;
size = sizeof(SLang_BString_Type);
if (type == IS_BSTRING)
{
unsigned int dlen = BSTRING_EXTRA_BYTES(len);
malloced_len = len + dlen;
if ((malloced_len < len)
|| (size + malloced_len < size))
{
SLang_verror (SL_Malloc_Error, "Unable to create a binary string of the desired size");
return NULL;
}
size += malloced_len;
}
if (NULL == (b = (SLang_BString_Type *)SLmalloc (size)))
return NULL;
b->len = len;
b->malloced_len = malloced_len;
b->num_refs = 1;
b->ptr_type = type;
switch (type)
{
default:
case IS_BSTRING:
if (bytes != NULL) memcpy ((char *) b->v.bytes, bytes, len);
/* Now \0 terminate it because we want to also use it as a C string
* whenever possible. Note that sizeof(SLang_BString_Type) includes
* space for 1 character and we allocated len extra bytes. Thus, it is
* ok to add a \0 to the end.
*/
b->v.bytes[len] = 0;
break;
case IS_SLSTRING:
if (NULL == (b->v.ptr = (unsigned char *)SLang_create_nslstring (bytes, len)))
{
SLfree ((char *) b);
return NULL;
}
break;
case IS_MALLOCED:
case IS_NOT_TO_BE_FREED:
b->v.ptr = (unsigned char *)bytes;
bytes [len] = 0; /* NULL terminate */
break;
}
return b;
}
示例10: SLmalloc
static Stdio_MMT_List_Type *alloc_stdio_list_elem (void)
{
Stdio_MMT_List_Type *elem;
elem = (Stdio_MMT_List_Type *) SLmalloc(sizeof(Stdio_MMT_List_Type));
if (elem != NULL)
memset ((char *)elem, 0, sizeof (Stdio_MMT_List_Type));
return elem;
}
示例11: SLang_doerror
void SLang_doerror (char *error)
{
char *str = NULL;
char *err;
char *malloced_err_buf;
char err_buf [1024];
malloced_err_buf = NULL;
if (((SLang_Error == SL_USER_ERROR)
|| (SLang_Error == SL_USAGE_ERROR))
&& (error != NULL) && (*error != 0))
err = error;
else
{
char *sle = "S-Lang Error: ";
unsigned int len = 0;
char *fmt = "%s%s%s";
str = get_error_string ();
if ((error == NULL) || (*error == 0))
error = "";
else if (SLang_Error == SL_UNKNOWN_ERROR)
/* Do not display an unknown error message if error is non-NULL */
str = "";
else {
fmt = "%s%s: %s";
len = 2; /* ": " */
}
len += strlen (sle) + strlen (str) + strlen(error) + 1 /* trailing 0 */;
err = err_buf;
if (len > sizeof (err_buf))
{
if (NULL == (malloced_err_buf = SLmalloc (len)))
err = NULL;
else
err = malloced_err_buf;
}
if (err != NULL) sprintf (err, fmt, sle, str, error);
else err = "Out of memory";
}
if (SLang_Error_Hook == NULL)
{
fputs (err, stderr);
fputs("\r\n", stderr);
fflush (stderr);
}
else
(*SLang_Error_Hook)(err);
SLfree (malloced_err_buf);
}
示例12: memset
/* reverse index converter from John Davis */
static SLang_Array_Type *convert_reverse_indices (SLindex_Type *r, SLindex_Type num_r, SLindex_Type num_h)
{
SLang_Array_Type *new_r;
SLang_Array_Type **new_r_data;
SLindex_Type i, *lens;
if (NULL == (new_r = SLang_create_array (SLANG_ARRAY_TYPE, 0, NULL, &num_h, 1)))
return NULL;
if (NULL == (lens = (SLindex_Type *)SLmalloc (num_h * sizeof (SLindex_Type))))
{
SLang_free_array (new_r);
return NULL;
}
memset ((char *)lens, 0, num_h*sizeof(SLindex_Type));
for (i = 0; i < num_r; i++)
{
SLindex_Type r_i = r[i];
if (r_i >= 0)
lens[r_i]++;
}
new_r_data = (SLang_Array_Type **) new_r->data;
for (i = 0; i < num_h; i++)
{
if (NULL == (new_r_data[i] = SLang_create_array (SLANG_ARRAY_INDEX_TYPE, 0, NULL, &lens[i], 1)))
goto return_error;
lens[i] = 0;
}
for (i = 0; i < num_r; i++)
{
SLang_Array_Type *at;
SLindex_Type r_i = r[i];
if (r_i < 0)
continue;
at = new_r_data[r_i];
((SLindex_Type *)at->data)[lens[r_i]] = i;
lens[r_i]++;
}
SLfree ((char *)lens);
return new_r;
return_error:
SLfree ((char *) lens);
SLang_free_array (new_r);
return NULL;
}
示例13: SLclass_add_binary_op
int SLclass_add_binary_op (SLtype a, SLtype b,
int (*f) (int,
SLtype, VOID_STAR, unsigned int,
SLtype, VOID_STAR, unsigned int,
VOID_STAR),
int (*r) (int, SLtype, SLtype, SLtype *))
{
SL_OOBinary_Type *ab;
SLang_Class_Type *cl;
if ((f == NULL) || (r == NULL)
|| ((a == SLANG_VOID_TYPE) && (b == SLANG_VOID_TYPE)))
{
_pSLang_verror (SL_INVALID_PARM, "SLclass_add_binary_op");
return -1;
}
if (NULL == (ab = (SL_OOBinary_Type *) SLmalloc (sizeof(SL_OOBinary_Type))))
return -1;
ab->binary_function = f;
ab->binary_result = r;
if (a == SLANG_VOID_TYPE)
{
cl = _pSLclass_get_class (b);
ab->data_type = a;
ab->next = NULL;
cl->cl_void_binary_this = ab;
}
else if (b == SLANG_VOID_TYPE)
{
cl = _pSLclass_get_class (a);
ab->data_type = b;
ab->next = NULL;
cl->cl_this_binary_void = ab;
}
else
{
cl = _pSLclass_get_class (a);
ab->next = cl->cl_binary_ops;
ab->data_type = b;
cl->cl_binary_ops = ab;
}
if ((a != SLANG_ARRAY_TYPE)
&& (b != SLANG_ARRAY_TYPE))
{
if ((-1 == _pSLarray_add_bin_op (a))
|| (-1 == _pSLarray_add_bin_op (b)))
return -1;
}
return 0;
}
示例14: sizeof
static Png_Type *alloc_png_type (int mode)
{
Png_Type *p;
if (NULL != (p = (Png_Type *)SLmalloc (sizeof (Png_Type))))
{
memset ((char *) p, 0, sizeof (Png_Type));
p->mode = mode;
}
return p;
}
示例15: _pSLstring_list_init
int _pSLstring_list_init (_pSLString_List_Type *p, unsigned int max_num, unsigned int delta_num)
{
if (NULL == (p->buf = (char **) SLmalloc (max_num * sizeof (char *))))
return -1;
p->max_num = max_num;
p->num = 0;
p->delta_num = delta_num;
p->is_malloced = 0;
return 0;
}