tc008_01_mem.c.svn-base

来自「RT-Thread是发展中的下一代微内核嵌入式实时操作系统」· SVN-BASE 代码 · 共 56 行

SVN-BASE
56
字号
/*
 * File      : tc008_01_mem.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006, RT-Thread Development Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rt-thread.com/license/LICENSE.
 *
 * Change Logs:
 * Date           Author       Notes
 * 2006-06-08     Bernard      the first version
 */

#include <rtthread.h>

struct rt_thread thread1;
char thread1_stack[512];

void thread1_entry(void* parameter)
{
	int i;
	char *ptr[32];
	
	for (i = 0; i < 32; i ++) ptr[i] = RT_NULL;

	while(1)
	{
		for (i = 0; i < 32; i++)
		{
			ptr[i] = rt_malloc(1 << i);
			
			if (ptr[i] != RT_NULL)
			{
				rt_kprintf("get memory: 0x%x\n", ptr[i]);
				rt_free(ptr[i]);
				
				ptr[i] = RT_NULL;
			}
		}
	}
}

int rt_application_init()
{
	rt_thread_init(&thread1,
		"thread1",
		thread1_entry, RT_NULL,
		&thread1_stack[0], sizeof(thread1_stack),
		200, 100);

	rt_thread_startup(&thread1);
  		  
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?