From: "Dan Conti" <danc@fullplaymedia.com>
To: <ecos-discuss@sources.redhat.com>
Subject: RE: [ECOS] malloc vs. new
Date: Sun, 23 Jun 2002 14:40:00 -0000 [thread overview]
Message-ID: <D8DFF0AFE792914996F997E68FEC3A484F66D9@bunker.iobjects.com> (raw)
new shouldn't be broken, since it just calls malloc. does malloc work
when making allocations of the exact same size?
two things to try as workarounds:
1) write your own operator new/new[]/delete/delete[]. tossing the
following into some file should work:
void* operator new(size_t size) {
return malloc(size_t);
}
void operator delete(void* ptr) {
if( ptr )
free(ptr);
}
make versions for new[] and delete[] also, which are the same function
with different names.
2) use placement new, which is what you were getting at below. be wary
of alignment considerations for the buffer you use. also at clean up you
have to manually call the destructor IIRC. C++ is not my forte.
#include <new.h>
char buffer[1024] __attribute__((align(4));
CObject* pObj = new(buffer) CObject();
...
pObj->~CObject();
Good luck.
-----Original Message-----
From: Scott Dattalo [mailto:scott@dattalo.com]
Sent: Friday, June 21, 2002 7:18 PM
To: ecos-discuss@sources.redhat.com
Subject: [ECOS] malloc vs. new
In a project I'm porting to eCos there is some C++ code. Consequently,
there are several new() calls for creating new objects. Unfortunately,
calls to new() hang. Specifically, the kernel is unable to allocate
memory
and throws an exception. This switches control to the exception thread
and
control is never released...
Calls to malloc, OTOH, work just fine.
I've sifted through the documentation and the best I could come up with
is
this snippet:
#define MEMORY_BUFFER 0x1000
char StaticMemoryBuffer[MEMORY_BUFFER];
...
cyg_handle_t mempool;
cyg_mempool_var mempool_obj;
cyg_mempool_var_create(StaticMemoryBuffer, MEMORY_BUFFER, &mempool,
&mempool_obj);
This still fails. How does one provide a memory allocation buffer for
new()?
Scott
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss
next reply other threads:[~2002-06-22 19:25 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-23 14:40 Dan Conti [this message]
2002-06-23 14:56 ` Scott Dattalo
2002-06-24 4:27 ` Pierre Merlin
2002-06-24 13:25 ` Scott Dattalo
2002-06-24 13:27 ` Scott Dattalo
2002-06-24 15:07 ` Gary Thomas
2002-06-24 19:05 ` Scott Dattalo
2002-06-25 2:32 ` Tim Drury
2002-06-25 6:45 ` Kjell Svensson
[not found] ` <200206250843.51339.tdrury@siliconmotorsports.com>
2002-06-25 11:12 ` Kjell Svensson
-- strict thread matches above, loose matches on Subject: below --
2002-06-27 1:48 Koeller, T.
2002-06-26 9:12 Koeller, T.
2002-06-26 3:38 Koeller, T.
2002-06-26 8:57 ` Tim Drury
2002-06-25 4:51 Koeller, T.
2002-06-25 7:00 ` Tim Drury
2002-06-25 11:20 ` Daniel Leu
2002-06-25 23:38 ` Tim Drury
2002-06-21 20:02 Scott Dattalo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D8DFF0AFE792914996F997E68FEC3A484F66D9@bunker.iobjects.com \
--to=danc@fullplaymedia.com \
--cc=ecos-discuss@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).