Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training


Allocating memory on heap

Posted by Nobody/Anonymous on May 17, 2005
I am planning to use a linked list to create a data buffer with elements of different sizes. For this I need to be able to allocate memory with pvPortMalloc, problem is that I am running out of heap quite easy. Which heap-allocation file should I use?? Since the list will be used frequently, alloc and free will be used a lot, and with different sizes I shouldn't use heap_2. Heap_1 can't free memory. Heap_3 uses ordinary alloc/free.

Is it a bad idea to implement a dynamic data buffer using freeRTOS??

Grateful for suggestions!

RE: Allocating memory on heap

Posted by Richard on May 17, 2005

Embedded systems have a wide variety of memory allocation requirements. A scheme that is good for one system will be terrible for another. The three schemes that come in the download are just intended to be examples of possible solutions. It is common that they are not suited to a particular application.

The pvPortMalloc() and vPortFree() functions are used by the kernel to allocate memory actually required by the kernel. For example when a task is created memory is allocated for the task stack. The kernel heap (sized by configTOTAL_HEAP_SIZE) must be large enough for the kernel needs - but there is no reason why you do not have another memory area for your application needs.

You have a couple of alternatives:

1) If you define configTOTAL_HEAP_SIZE to be the size required by the kernel, then calls to pvPortMalloc() within the kernel code will use this memory area with the heap_1, heap_c or heap_3 implementation. You could then define another memory area that uses [for example] MyMalloc() and MyFree() to allocate and free memory using any other scheme of your choice. Your application heap and the kernel heap are then separate.

2) Replace the scheme in heap_1 or heap_2 either with one of your own writing, or with another open source scheme if you can find one appropriate. For example, take a look at the wizC PIC18 FreeRTOS port pages on the WEB site. These include a link to a memory allocation scheme written by Marcel Van Lieshout for use with his port. Maybe this is useful to you?

Take care when choosing an implementation as many generic implementations are very slow and nondeterministic.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]

Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.

Free TCP/IP and file system demos for the RTOS

Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑

FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists