本文整理汇总了C++中rt_malloc函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_malloc函数的具体用法?C++ rt_malloc怎么用?C++ rt_malloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_malloc函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: zrec_files
/* receive files */
static rt_err_t zrec_files(struct zfile *zf)
{
rt_uint8_t *rxbuf;
rt_err_t res = -RT_ERROR;
zinit_parameter();
rxbuf = rt_malloc(RX_BUFFER_SIZE*sizeof(rt_uint8_t));
if (rxbuf == RT_NULL) {
rt_kprintf("rxbuf: out of memory\r\n");
return -RT_ERROR;
}
rt_kprintf("\r\nrz: ready...\r\n"); /* here ready to receive things */
if ((res = zrec_init(rxbuf,zf))!= RT_EOK) {
rt_kprintf("\b\b\breceive init failed\r\n");
rt_free(rxbuf);
return -RT_ERROR;
}
res = zrec_file(rxbuf,zf);
if (res == ZFIN) {
rt_free(rxbuf);
return RT_EOK; /* if finish session */
} else if (res == ZCAN) {
rt_free(rxbuf);
return ZCAN; /* cancel by sender */
} else {
zsend_can();
rt_free(rxbuf);
return res;
}
}
开发者ID:malooei,项目名称:yeejoin-workspace,代码行数:31,代码来源:rz.c
示例2: player_update_list
void player_update_list()
{
int index;
struct play_item* item;
if (music_listitems != RT_NULL)
{
for (index = 0; index < music_listitems_size; index ++)
{
rt_free(music_listitems[index].name);
}
rt_free(music_listitems);
music_listitems = RT_NULL;
music_listitems_size = 0;
}
music_listitems_size = play_list_items();
if (music_listitems_size > 0)
{
music_listitems = (struct rtgui_listbox_item*) rt_malloc (
music_listitems_size * sizeof(struct rtgui_listbox_item));
for (index = 0; index < music_listitems_size; index ++)
{
music_listitems[index].image = RT_NULL;
item = play_list_item(index);
music_listitems[index].name = rt_strdup(item->title);
}
}
/* re-set listbox items */
rtgui_listbox_set_items(music_listbox,
music_listitems, music_listitems_size);
}
开发者ID:eyyhappy,项目名称:network-radio,代码行数:34,代码来源:player_ui.c
示例3: rt_msgq_init
RTAI_SYSCALL_MODE int rt_msgq_init(RT_MSGQ *mq, int nmsg, int msg_size)
{
int i;
void *p;
if (!(mq->slots = rt_malloc((msg_size + RT_MSGH_SIZE + sizeof(void *))*nmsg + RT_MSGH_SIZE))) {
return -ENOMEM;
}
mq->nmsg = nmsg;
mq->fastsize = msg_size;
mq->slot = 0;
p = mq->slots + nmsg;
for (i = 0; i < nmsg; i++) {
mq->slots[i] = p;
((RT_MSGH *)p)->priority = 0;
p += (msg_size + RT_MSGH_SIZE);
}
((RT_MSGH *)(mq->firstmsg = p))->priority = (0xFFFFFFFF/2);
rt_typed_sem_init(&mq->receivers, 1, RES_SEM);
rt_typed_sem_init(&mq->senders, 1, RES_SEM);
rt_typed_sem_init(&mq->received, 0, CNT_SEM);
rt_typed_sem_init(&mq->freslots, nmsg, CNT_SEM);
spin_lock_init(&mq->lock);
return 0;
}
开发者ID:ArcEye,项目名称:3.4.55-rtai,代码行数:25,代码来源:tbx.c
示例4: dlopen
void* dlopen(const char *filename, int flags)
{
rt_module_t module;
char *fullpath;
const char*def_path = MODULE_ROOT_DIR;
/* check parameters */
RT_ASSERT(filename != RT_NULL);
if (filename[0] != '/') /* it's a absolute path, use it directly */
{
fullpath = rt_malloc(strlen(def_path) + strlen(filename) + 2);
/* join path and file name */
rt_snprintf(fullpath, strlen(def_path) + strlen(filename) + 2,
"%s/%s", def_path, filename);
}
/* find in module list */
module = rt_module_find(fullpath);
if(module != RT_NULL) module->nref++;
else module = rt_module_open(fullpath);
rt_free(fullpath);
return (void*)module;
}
开发者ID:pengdonglin137,项目名称:iboot,代码行数:27,代码来源:dlopen.c
示例5: resp_handler
static void resp_handler(struct spi_wifi_eth *wifi_device, struct spi_wifi_resp *resp)
{
struct spi_wifi_resp *resp_return;
switch (resp->cmd)
{
case SPI_WIFI_CMD_INIT:
WIFI_DEBUG("resp_handler SPI_WIFI_CMD_INIT\n");
resp_return = (struct spi_wifi_resp *)rt_malloc(sizeof(struct spi_wifi_resp)); //TODO:
memcpy(resp_return, resp, 10);
rt_mb_send(&wifi_device->spi_wifi_cmd_mb, (rt_uint32_t)resp_return);
break;
case SPI_WIFI_CMD_SCAN:
WIFI_DEBUG("resp_handler SPI_WIFI_CMD_SCAN\n");
break;
case SPI_WIFI_CMD_JOIN:
WIFI_DEBUG("resp_handler SPI_WIFI_CMD_JOIN\n");
wifi_device->active = 1;
eth_device_linkchange(&wifi_device->parent, RT_TRUE);
break;
default:
WIFI_DEBUG("resp_handler %d\n", resp->cmd);
break;
}
}
开发者ID:damoxinjiang,项目名称:rt-thread,代码行数:29,代码来源:spi_wifi_rw009.c
示例6: rs485_system_init
int rs485_system_init(void)
{
rt_err_t result;
rt_thread_t init_thread;
rs485_send_mut = rt_mutex_create("rs485mut",RT_IPC_FLAG_FIFO);
rs485_data_init();
uart1_dev_my = (struct _uart_dev_my*)rt_malloc(sizeof(struct _uart_dev_my));
if (uart1_dev_my == RT_NULL)
{
rt_kprintf("no memory for shell\n");
return -1;
}
memset(uart1_dev_my, 0, sizeof(struct _uart_dev_my));
rt_sem_init(&(uart1_dev_my->rx_sem), "rs485rx", 0, 0);
uart1_dev_my->device = RT_NULL;
uart1_rs485_set_device();
uart1_sem = rt_sem_create("uart1_sem",0, RT_IPC_FLAG_FIFO);
init_thread = rt_thread_create("rs485",rt_rs485_thread_entry, RT_NULL,
4092, 8, 21);
if (init_thread != RT_NULL)
rt_thread_startup(init_thread);
return 0;
}
开发者ID:pigeon0411,项目名称:eb120_ec11,代码行数:35,代码来源:rs485_decode.c
示例7: xdr_opaque_auth
AUTH *authnone_create()
{
register struct authnone_private *ap = authnone_private;
XDR xdr_stream;
register XDR *xdrs;
extern bool_t xdr_opaque_auth(XDR *xdrs, struct opaque_auth *ap);
if (ap == 0) {
ap = (struct authnone_private *) rt_malloc (sizeof(*ap));
if (ap == 0) return NULL;
memset(ap, 0, sizeof(*ap));
authnone_private = ap;
}
if (!ap->mcnt) {
ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
ap->no_client.ah_ops = &ops;
xdrs = &xdr_stream;
xdrmem_create(xdrs, ap->marshalled_client,
(unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
ap->mcnt = XDR_GETPOS(xdrs);
XDR_DESTROY(xdrs);
}
return (&ap->no_client);
}
开发者ID:AdrianHuang,项目名称:rt-thread-for-vmm,代码行数:26,代码来源:auth_none.c
示例8: rt_thread_create
/**
* This function will create a thread object and allocate thread object memory
* and stack.
*
* @param name the name of thread, which shall be unique
* @param entry the entry function of thread
* @param parameter the parameter of thread enter function
* @param stack_size the size of thread stack
* @param priority the priority of thread
* @param tick the time slice if there are same priority thread
*
* @return the created thread object
*/
rt_thread_t rt_thread_create(const char *name,
void (*entry)(void *parameter),
void *parameter,
rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick)
{
struct rt_thread *thread;
void *stack_start;
thread = (struct rt_thread *)rt_object_allocate(RT_Object_Class_Thread,
name);
if (thread == RT_NULL)
return RT_NULL;
stack_start = (void *)rt_malloc(stack_size);
if (stack_start == RT_NULL)
{
/* allocate stack failure */
rt_object_delete((rt_object_t)thread);
return RT_NULL;
}
_rt_thread_init(thread,
name,
entry,
parameter,
stack_start,
stack_size,
priority,
tick);
return thread;
}
开发者ID:QiuGong,项目名称:Terminal,代码行数:48,代码来源:thread.c
示例9: rt_object_allocate
/**
* This function will allocate an object from object system
*
* @param type the type of object
* @param name the object name. In system, the object's name must be unique.
*
* @return object
*/
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char* name)
{
struct rt_object* object;
register rt_base_t temp;
struct rt_object_information* information;
RT_DEBUG_NOT_IN_INTERRUPT;
#ifdef RT_USING_MODULE
/* get module object information, module object should be managed by kernel object container */
information = (rt_module_self() != RT_NULL && (type != RT_Object_Class_Module)) ?
&rt_module_self()->module_object[type] : &rt_object_container[type];
#else
/* get object information */
information = &rt_object_container[type];
#endif
object = (struct rt_object*)rt_malloc(information->object_size);
if (object == RT_NULL)
{
/* no memory can be allocated */
return RT_NULL;
}
/* initialize object's parameters */
/* set object type */
object->type = type;
/* set object flag */
object->flag = 0;
#ifdef RT_USING_MODULE
if(rt_module_self() != RT_NULL)
{
object->flag |= RT_OBJECT_FLAG_MODULE;
}
object->module_id = (void*)rt_module_self();
#endif
/* copy name */
for (temp = 0; temp < RT_NAME_MAX; temp ++)
{
object->name[temp] = name[temp];
}
RT_OBJECT_HOOK_CALL(rt_object_attach_hook, (object));
/* lock interrupt */
temp = rt_hw_interrupt_disable();
/* insert object into information object list */
rt_list_insert_after(&(information->object_list), &(object->list));
/* unlock interrupt */
rt_hw_interrupt_enable(temp);
/* return object */
return object;
}
开发者ID:comrid1987,项目名称:jb3500,代码行数:68,代码来源:object.c
示例10: memp_malloc_fn
memp_malloc_fn(memp_t type, const char* file, const int line)
#endif
{
void* ptr;
rt_uint32_t size, level;
size = memp_sizes[type];
LWIP_DEBUGF(MEMP_DEBUG, ("memp malloc %s, size %d, ", memp_desc[type], memp_sizes[type]));
level = rt_hw_interrupt_disable();
if (type == MEMP_TCP_PCB)
{
if (tcp_pcbs >= MEMP_NUM_TCP_PCB)
{
rt_hw_interrupt_enable(level);
return RT_NULL;
}
else
{
/* increased tcp pcb allocated number */
tcp_pcbs ++;
}
}
rt_hw_interrupt_enable(level);
ptr = rt_malloc(size);
LWIP_DEBUGF(MEMP_DEBUG, ("mem 0x%x\n", ptr));
return ptr;
}
开发者ID:samkrew,项目名称:nxp-lpc,代码行数:30,代码来源:memp_tiny.c
示例11: rt_malloc
static char *winpath_dirdup(char *des, const char *src)
{
char *path;
int i = 0;
path = rt_malloc(FILE_PATH_MAX);
if (path == RT_NULL)
return RT_NULL;
strcpy(path, des);
strcat(path, src);
while (1)
{
if (path[i] == 0)
break;
if (path[i] == '/')
path[i] = '\\';
i++;
}
return path;
}
开发者ID:bright-pan,项目名称:smart-lock,代码行数:25,代码来源:dfs_win32.c
示例12: rt_hw_lcd_init
int rt_hw_lcd_init(const char *name)
{
struct lcd_device *dev;
if(rt_device_find(name))
{
return -RT_EIO;
}
dev = rt_malloc(sizeof(struct lcd_device));
if(!dev)
{
return RT_ENOMEM;
}
dev->rtdev.type = RT_Device_Class_Graphic;
dev->rtdev.rx_indicate = RT_NULL;
dev->rtdev.init = rt_lcd_init;
dev->rtdev.open = RT_NULL;
dev->rtdev.close = RT_NULL;
dev->rtdev.read = RT_NULL;
dev->rtdev.write = RT_NULL;
dev->rtdev.control = rt_lcd_control;
dev->rtdev.user_data = RT_NULL;
/* initialize mutex */
rt_mutex_init(&dev->lock, name, RT_IPC_FLAG_FIFO);
rt_device_register(&dev->rtdev, name, RT_DEVICE_FLAG_RDWR);
return RT_EOK;
}
开发者ID:yanbib,项目名称:smartcar,代码行数:31,代码来源:drv_lcd.c
示例13: rt_hw_dc_init
void rt_hw_dc_init(void)
{
rt_device_t dc = rt_malloc(sizeof(struct rt_device));
if (dc == RT_NULL)
{
rt_kprintf("dc == RT_NULL\n");
return; /* no memory yet */
}
_dc_info.bits_per_pixel = 16;
_dc_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565P;
_dc_info.framebuffer = (rt_uint8_t*)HW_FB_ADDR;
_dc_info.width = FB_XSIZE;
_dc_info.height = FB_YSIZE;
/* init device structure */
dc->type = RT_Device_Class_Graphic;
dc->init = rt_dc_init;
dc->open = RT_NULL;
dc->close = RT_NULL;
dc->control = rt_dc_control;
dc->user_data = (void*)&_dc_info;
/* register Display Controller device to RT-Thread */
rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR);
}
开发者ID:304471720,项目名称:rt-thread,代码行数:26,代码来源:display_controller.c
示例14: mainmenu_scan_apps
static void mainmenu_scan_apps(void)
{
DIR *dir;
struct dirent *dirent;
char *path_buf;
path_buf = rt_malloc(DFS_PATH_MAX);
if (!path_buf)
return;
dir = opendir("/programs/");
if (dir == RT_NULL)
goto _ret;
do
{
dirent = readdir(dir);
if (dirent == RT_NULL)
break;
if (strcmp(dirent->d_name, ".") == 0)
continue;
/* readdir is not guaranteed to return "..". So we should deal with
* it specially. */
if (strcmp(dirent->d_name, "..") == 0)
continue;
mainmenu_register_app(dirent->d_name);
}
while (dirent != RT_NULL);
closedir(dir);
_ret:
rt_free(path_buf);
}
开发者ID:003900107,项目名称:realboard-lpc4088,代码行数:35,代码来源:mainmenu.c
示例15: _send
static int _send(RT_MSGQ *mq, void *msg, int msg_size, int msgpri, int space)
{
unsigned long flags;
RT_MSG *msg_ptr;
void *p;
if (msg_size > mq->fastsize) {
if (!(p = rt_malloc(msg_size))) {
rt_sem_signal(&mq->freslots);
rt_sem_signal(&mq->senders);
return -ENOMEM;
}
} else {
p = NULL;
}
flags = rt_spin_lock_irqsave(&mq->lock);
msg_ptr = mq->slots[mq->slot++];
rt_spin_unlock_irqrestore(flags, &mq->lock);
msg_ptr->hdr.size = msg_size;
msg_ptr->hdr.priority = msgpri;
msg_ptr->hdr.malloc = p;
msg_ptr->hdr.broadcast = 0;
if (space) {
memcpy(p ? p : msg_ptr->msg, msg, msg_size);
} else {
rt_copy_from_user(p ? p : msg_ptr->msg, msg, msg_size);
}
flags = rt_spin_lock_irqsave(&mq->lock);
enq_msg(mq, &msg_ptr->hdr);
rt_spin_unlock_irqrestore(flags, &mq->lock);
rt_sem_signal(&mq->received);
rt_sem_signal(&mq->senders);
return 0;
}
开发者ID:ArcEye,项目名称:3.4.55-rtai,代码行数:34,代码来源:tbx.c
示例16: dfs_elm_rename
int dfs_elm_rename(struct dfs_filesystem *fs, const char *oldpath, const char *newpath)
{
FRESULT result;
#if _VOLUMES > 1
char *drivers_oldfn;
const char *drivers_newfn;
int vol;
extern int elm_get_vol(FATFS * fat);
/* add path for ELM FatFS driver support */
vol = elm_get_vol((FATFS *)fs->data);
if (vol < 0)
return -DFS_STATUS_ENOENT;
drivers_oldfn = rt_malloc(256);
if (drivers_oldfn == RT_NULL)
return -DFS_STATUS_ENOMEM;
drivers_newfn = newpath;
rt_snprintf(drivers_oldfn, 256, "%d:%s", vol, oldpath);
#else
const char *drivers_oldfn, *drivers_newfn;
drivers_oldfn = oldpath;
drivers_newfn = newpath;
#endif
result = f_rename(drivers_oldfn, drivers_newfn);
#if _VOLUMES > 1
rt_free(drivers_oldfn);
#endif
return elm_result_to_dfs(result);
}
开发者ID:gastonfeng,项目名称:rt-thread,代码行数:34,代码来源:dfs_elm.c
示例17: tcpip_input
err_t
tcpip_input(struct pbuf *p, struct netif *inp)
{
int i;
u8_t *pdata;
if (uip_len)
{
uip_arp_out();
if (( pdata =(u8_t*)rt_malloc(1500*sizeof(u8_t))) == RT_NULL)
{
pbuf_free(p);
return 1;
}
for (i=0; i < (UIP_LLH_LEN + 40); ++i) // 14+40 =54
{
pdata[i] = uip_buf[i]; /* get dest an src ipaddr */
}
// Copy the data portion part
for(; i < uip_len; ++i)
{
pdata[i] = uip_appdata[i - UIP_LLH_LEN - 40 ];
}
p ->payload = pdata;
p->len = uip_len;
inp->linkoutput(inp,p);
rt_free(pdata);
return 1;
}
else
{
pbuf_free(p);
return 0;
}
}
开发者ID:634351070,项目名称:rt-thread,代码行数:34,代码来源:uip_tcpip.c
示例18: net_buf_init
void net_buf_init(rt_size_t size)
{
rt_thread_t tid;
/* init net buffer structure */
_netbuf.read_index = _netbuf.save_index = 0;
_netbuf.size = size; /* net buffer size */
/* allocate buffer */
_netbuf.buffer_data = rt_malloc(_netbuf.size);
_netbuf.data_length = 0;
/* set ready and resume water mater */
_netbuf.ready_wm = _netbuf.size * 90/100;
_netbuf.resume_wm = _netbuf.size * 80/100;
/* set init stat */
_netbuf.stat = NETBUF_STAT_STOPPED;
rt_kprintf("stat -> stopped\n");
_netbuf.wait_ready = rt_sem_create("nready", 0, RT_IPC_FLAG_FIFO);
_netbuf.wait_resume = rt_sem_create("nresum", 0, RT_IPC_FLAG_FIFO);
_netbuf.is_wait_ready = RT_FALSE;
/* crate message queue */
_netbuf_mq = rt_mq_create("njob", sizeof(struct net_buffer_job),
4, RT_IPC_FLAG_FIFO);
/* create net buffer thread */
tid = rt_thread_create("nbuf",
net_buf_thread_entry, RT_NULL,
1024, 22, 5);
if (tid != RT_NULL)
rt_thread_startup(tid);
}
开发者ID:18337129968,项目名称:-android-source-code,代码行数:35,代码来源:netbuffer.c
示例19: rthw_wifi_scan
int rthw_wifi_scan(scan_callback_fn fun, void *data)
{
struct scan_user_data *user_data;
if (fun == RT_NULL)
{
rt_kprintf("scan callback fun is null\n");
return -1;
}
user_data = rt_malloc(sizeof(struct scan_user_data));
if (user_data == RT_NULL)
{
rt_kprintf("wifi scan malloc fail\n");
return -1;
}
user_data->fun = fun;
user_data->data = data;
if (wifi_scan_networks(rthw_wifi_scan_result_handler, user_data) != RTW_SUCCESS)
{
rt_kprintf("ERROR: wifi scan failed\n\r");
return -1;
}
return 0;
}
开发者ID:AlexShiLucky,项目名称:rt-thread,代码行数:26,代码来源:drv_wlan.c
示例20: calibration_entry
void calibration_entry(void* parameter)
{
rt_device_t device;
struct rtgui_rect rect;
struct setup_items setup;
device = rt_device_find("touch");
if (device == RT_NULL) return; /* no this device */
calibration_ptr = (struct calibration_session*)
rt_malloc(sizeof(struct calibration_session));
rt_memset(calibration_ptr, 0, sizeof(struct calibration_data));
calibration_ptr->device = device;
rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION,
(void*)calibration_data_post);
rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
/* set screen rect */
calibration_ptr->width = rect.x2;
calibration_ptr->height = rect.y2;
calibration_ptr->app = rtgui_app_create("calibration");
if (calibration_ptr->app != RT_NULL)
{
/* create calibration window */
calibration_ptr->win = rtgui_win_create(RT_NULL,
"calibration", &rect,
RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER |
RTGUI_WIN_STYLE_ONTOP | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
if (calibration_ptr->win != RT_NULL)
{
rtgui_object_set_event_handler(RTGUI_OBJECT(calibration_ptr->win),
calibration_event_handler);
rtgui_win_show(calibration_ptr->win, RT_TRUE);
}
rtgui_app_destroy(calibration_ptr->app);
}
/* set calibration data */
rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION_DATA,
&calibration_ptr->data);
//save setup
setup.touch_min_x = calibration_ptr->data.min_x;
setup.touch_max_x = calibration_ptr->data.max_x;
setup.touch_min_y = calibration_ptr->data.min_y;
setup.touch_max_y = calibration_ptr->data.max_y;
setup_save(&setup);
/* recover to normal */
rt_device_control(calibration_ptr->device, RT_TOUCH_NORMAL, RT_NULL);
/* release memory */
rt_free(calibration_ptr);
calibration_ptr = RT_NULL;
}
开发者ID:suzuki8,项目名称:realtouch-stm32f4,代码行数:59,代码来源:calibration.c
注:本文中的rt_malloc函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论