# Direct using pvPortMalloc() and vPortFree() 

**URL:** <https://forums.freertos.org/t/direct-using-pvportmalloc-and-vportfree/31>\
**Category:** Kernel\
**Created:** [November 10, 2013, 2:23pm UTC](https://forums.freertos.org/t/direct-using-pvportmalloc-and-vportfree/31 "2013-11-10T14:23:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [November 10, 2013, 2:23pm UTC](https://forums.freertos.org/t/direct-using-pvportmalloc-and-vportfree/31/1 "2013-11-10T14:23:53Z")

</div>

**[znatok](https://sourceforge.net/u/znatok/)** wrote on [Sunday, November 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/032bc6bf/#7b5c):

Hi,  
In my application I need some malloc/free mechanism. Considering that FreeRTOS already has pvPortMalloc() and vPortFree() I plan to use this functions instead of invoacation of the standard library. I have a few questions regarding this:

1. Is it generally OK to use FreeRTOS for heap management not only related to FreeRTOS resources.
2. Are this functions thread safe?
3. I’m currently using heap\_2. I’ve read about fragmentation problem so I plan to pass to heap\_4 unless heap\_2 has best match allocation? I mean if I’m going to allocate and free blocks of let’s say 100 and 50 bytes in random order am I going to end up with memory luck for 100 bytes block (as all memory will be 50 bytes fragmented)?

Thanks.

---

<div class="post-metadata">

**Author:** ![rtel](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/rtel/32/31_2.png) [@rtel](https://forums.freertos.org/u/rtel)\
**Post date:** [November 10, 2013, 2:45pm UTC](https://forums.freertos.org/t/direct-using-pvportmalloc-and-vportfree/31/2 "2013-11-10T14:45:43Z")

</div>

**[rtel](https://sourceforge.net/u/rtel/)** wrote on [Sunday, November 10, 2013](https://sourceforge.net/p/freertos/discussion/382005/thread/032bc6bf/#104a):

Yes it is fine to use pvPortMalloc() and vPortFree() in the application.

Yes they are thread safe.

Best to use heap\_4.c

Regards.
