# C++ new/delete vs adl\_memGet

**URL:** <https://forum.sierrawireless.com/t/c-new-delete-vs-adl-memget/4613>\
**Category:** Open AT\
**Created:** [August 12, 2010, 2:40pm UTC](https://forum.sierrawireless.com/t/c-new-delete-vs-adl-memget/4613 "2010-08-12T14:40:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cory\_johannsen](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cory\_johannsen](https://forum.sierrawireless.com/u/cory_johannsen)\
**Post date:** [August 12, 2010, 2:40pm UTC](https://forum.sierrawireless.com/t/c-new-delete-vs-adl-memget/4613/1 "2010-08-12T14:40:47Z")

</div>

I have been searching the forum but haven’t been able to locate an exact answer to my question. I am building a C++ OpenAT application for an SL6087 (using the most recent tools), and I need to perform some dynamic memory allocation. Should I be using the OpenAT adl\_memGet()/adl\_memRelease() functions or can I stick to new/delete semantics?

Sorry if this has already been answered, if so please point me to the appropriate thread with the information.

Thanks

---

<div class="post-metadata">

**Author:** ![cory\_johannsen](https://avatars.discourse-cdn.com/v4/letter/c/a9a28c/32.png) [@cory\_johannsen](https://forum.sierrawireless.com/u/cory_johannsen)\
**Post date:** [September 13, 2010, 6:55pm UTC](https://forum.sierrawireless.com/t/c-new-delete-vs-adl-memget/4613/2 "2010-09-13T18:55:44Z")

</div>

Well, it was in the documentation all onlg, but I just didn’t see it:  
In the advanced help section for Adding C++ to an OpenAT project:

Toolchain specificities  
Toolchains used in order to build the Open AT application have some specificities, which are listed below.

RTE mode  
RTE mode natively supports C++; there are no additional modifications or stubs to add to the application.

[b][u]Target mode  
Target mode requires a stub to be added for memory management (since new and delete C++ operators depend on standard C memory management functions). This stub is provided here, and has to be added to every Open AT application project which aims to embed C++ code.

ARM ELF GCC  
This toolchain has no specificities (except the need for the memory stub, explained just above). [/u][/b]

RVDS  
This toolchain requires some internal functions at the link stage as soon as C++ is used. These functions are provided in this stub, which has to be added to every Open AT application project compiled with the RVDS toolchain and which embeds C++ code.

## ADS C++ is not fully and correctly supported by this toolchain (no standard library, namespaces not supported). It is not recommended to use C++ with the ADS toolchain.

Referenced source code:

```auto
/*
 * memory_stub.c
 *
 * Created on: Sep 13, 2010
 * Author: cjohannsen
 */

#include "adl_global.h"

#ifndef __REMOTETASKS__

void *malloc(size_t n)
{
   return adl_memGet(n);
}

void free(void *p)
{
   if (p)
      adl_memRelease(p);
}

void *calloc(size_t n, size_t s)
{
   void *p = malloc(n*s);
   memset(p, 0, n*s);
   return p;
}

#endif
```

Bada-bing, bada-boom: new() and delete() function properly.

And I can definitely assure you that if you do not include this source file, you will get module resets every time you try and use new() or delete().

Cory
