LPC1830 sample code configTOTAL_HEAP_SIZE

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC1830 sample code configTOTAL_HEAP_SIZE

1,291 Views
kensu
Contributor V

Hi,

I want to know the "configTOTAL_HEAP_SIZE" in the LPC1830 freertos_blinky sample project.

#ifdef __CODE_RED
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16*1024 ) )

How to decide the 16*1024 for configTOTAL_HEAP_SIZE?

Thanks

Ken

Labels (1)
Tags (3)
0 Kudos
Reply
1 Reply

885 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hello Ken Su,

    At first, I think you need to know the heap and stack:

The heap is memory set aside for dynamic allocation. Unlike the stack, there's no enforced pattern to the allocation and deallocation of blocks from the heap; you can allocate a block at any time and free it at any time. This makes it much more complex to keep track of which parts of the heap are allocated or free at any given time; there are many custom heap allocators available to tune heap performance for different usage patterns.

The stack is the memory set aside as scratch space for a thread of execution. When a function is called, a block is reserved on the top of the stack for local variables and some bookkeeping data. When that function returns, the block becomes unused and can be used the next time a function is called. The stack is always reserved in a LIFO (last in first out) order; the most recently reserved block is always the next block to be freed. This makes it really simple to keep track of the stack; freeing a block from the stack is nothing more than adjusting one pointer.

   Heap can be applied by the user, and it shoule be release by the user, take an example:

p1 = (char *)malloc(10);

p1 is in the heap.

About your question:

#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 16*1024 ) )

If the size_t is 4 byte, then the heap size is 4*(16*1024)=65536.

If you don't use the malloc, I think you don't need to assign so much heap size, you even can defined it as 0, if you don't want to use it.

#ifdef __CODE_RED
#define configTOTAL_HEAP_SIZE  ( ( size_t ) ( 16*1024 ) )
#else
#define configTOTAL_HEAP_SIZE  ( ( size_t ) ( 0 ) )

 

The heap size for the whole MCU normally is defined in the link file.

17.jpg

 

Have a great day,
Kerry

 

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply