avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] adding wrapper functions for new and delete operators


From: David Brown
Subject: Re: [avr-libc-dev] adding wrapper functions for new and delete operators
Date: Mon, 07 Feb 2011 08:44:32 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7

On 05/02/2011 07:47, Bradley Jarvis wrote:
Hi
I use avr-gcc for c++ code (have so for years) and wanted to use new and
delete, particularly for libraries that I have written for and used in
an x86 environment which I didn't want to have to convert. So I wrote
the following wrapper functions, please feel free to add it to avr-libc

To go into a header file (not sure what the standard c++ header file new
and delete function would normally exist in, that that is where the
declarations would reside):

void *operator new(size_t);
void *operator new[](size_t);

void operator delete(void *);
void operator delete[](void *);


To go into the source file:

void *operator new(size_t s)
{
     return malloc(s);
}

void *operator new[](size_t s)
{
     return malloc(s);
}

void operator delete(void *m)
{
     free(m);
}

void operator delete[](void *m)
{
     free(m);
}


I have used these functions for years to get new and delete
functionality into my avr-gcc code.

BTW get job on the gcc avr support, it's a fantastic product. The only
other thing I would like to use that is not supported are exceptions, it
would make some software easier.

Thanks Brad


I haven't yet done very much C++, but doesn't the new() operator have to call the function's constructor, and the delete() call it's destructor? Or is that handled by the compiler automatically after it uses new() to get the memory area?

mvh.,

David




reply via email to

[Prev in Thread] Current Thread [Next in Thread]