# Heap and FreeRtos new

**URL:** <https://forums.freertos.org/t/heap-and-freertos-new/6558>\
**Category:** Kernel\
**Created:** [May 1, 2017, 5:08pm UTC](https://forums.freertos.org/t/heap-and-freertos-new/6558 "2017-05-01T17:08:09Z")\
**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:** [May 1, 2017, 5:08pm UTC](https://forums.freertos.org/t/heap-and-freertos-new/6558/1 "2017-05-01T17:08:09Z")

</div>

**[wiwix](https://sourceforge.net/u/wiwix/)** wrote on [Monday, May 01, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/c610c383/#3fbb):

Hi,

I’m facing strange issues in initialization phasis which begins to go out of my field of expertise. I searched for any recommandations on FreeRtos website about C++ integration but I didn’t find any good information about my issue (if it exists please point me to the right direction).

The fact is that when I use a C++ “new” statement, the constructor runs (checked with debugger), but several instructions latter (for instance after having build a parent class), I suddenly see the members to change value.

I think something is badly configured with my memory management, but I can’t figure out what. Could anyone help ?

I’m using heap\_1.c and I have overloading the new operators like this :

```auto
void * operator new( size_t size )
{
    return pvPortMalloc( size );
}

void * operator new[]( size_t size )
{
    return pvPortMalloc(size);
}

void operator delete( void * ptr )
{
    vPortFree ( ptr );
}

void operator delete[]( void * ptr )
{
    vPortFree ( ptr );
}

```

I also have made a call to \_\_libc\_init\_array() see my reset handler :

```auto
void Reset_Handler(void)
{
	uint32_t *pSrc, *pDest;

	/* Initialize the relocate segment */
	pSrc = &_etext;
	pDest = &_srelocate;

	if (pSrc != pDest) {
		for (; pDest < &_erelocate;) {
			*pDest++ = *pSrc++;
		}
	}

	/* Clear the zero segment */
	for (pDest = &_szero; pDest < &_ezero;) {
		*pDest++ = 0;
	}

	/* Set the vector table base address */
	pSrc = (uint32_t *) & _sfixed;
	SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);

	if (((uint32_t) pSrc >= IRAM0_ADDR) && ((uint32_t) pSrc < NFC_RAM_ADDR)) {
		SCB->VTOR |= (1UL) << SCB_VTOR_TBLBASE_Pos;
	}

    SystemInit();

    // Set Systick to 1ms interval, common to all SAM3 variants
    if (SysTick_Config(SystemCoreClock / 1000))
    {
      // Capture error
      while (1);
    }

    // Initialize board
    init();

    //Wait 1 ms
    uint32_t start = GetTickCount();
    do {
        yield();
    } while (GetTickCount() - start < 1);

    // Initialize C library
    __libc_init_array();

	/* Branch to main function */
	main();

	/* Infinite loop */
	while (1);
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [May 1, 2017, 7:25pm UTC](https://forums.freertos.org/t/heap-and-freertos-new/6558/2 "2017-05-01T19:25:57Z")

</div>

**[edwards3](https://sourceforge.net/u/edwards3/)** wrote on [Monday, May 01, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/c610c383/#4e01):

heap\_1 has no free(), so if you have descructors use heap\_4.
