C++ new/delete vs adl_memGet


#1

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


#2

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:

/*
 * 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