Hi,
did a search for previous posts, but could still not figure out what
I'm doing wrong in my code.
Due to some DMA hardware requirements (IBM Cell processor) I'm
attempting to overload new, new[], delete and delete[] with calls to
memalign() to insure that all objects and data is aligned to 16 byte
boundaries.
For some reason I'm getting "multiple definition of 'operator new'":
mpifxcorr-visibility.o: In function `operator new(unsigned int)':
/home/jr/correlator/mpifxcorr/src/cell-memory.h:32: multiple definition
of `operator new(unsigned int)'
mpifxcorr-mode.o:/home/jr/correlator/mpifxcorr/src/cell-memory.h:32:
first defined here
cell-memory.h :
#ifndef CELLMEMORY_H_
#define CELLMEMORY_H_
#include <new>
#include <exception // std::bad_alloc()
#include <cstdlib // (hmm, no memalign() here..?)
#include <malloc.h // for memalign()
using namespace std;
#define CELL_MEMALIGN 16
void* operator new (size_t size)
{
void *p;
p = memalign(CELL_MEMALIGN, size);
if (p==0) { throw std::bad_alloc(); } // for ANSI/ISO compliant
behavior
return p;
}
void* operator new[] (size_t size)
{
void *p;
p = memalign(CELL_MEMALIGN, size);
if (p==0) { throw std::bad_alloc(); } // for ANSI/ISO compliant
behavior
return p;
}
void operator delete (void *p)
{
free(p);
}
void operator delete[] (void *p)
{
free(p);
}
#endif
Any ideas? (Perhaps the problem is not in the above code?)
thanks,
- Jan 2 8842
JanW wrote:
Hi,
did a search for previous posts, but could still not figure out what
I'm doing wrong in my code.
Due to some DMA hardware requirements (IBM Cell processor) I'm
attempting to overload new, new[], delete and delete[] with calls to
memalign() to insure that all objects and data is aligned to 16 byte
boundaries.
For some reason I'm getting "multiple definition of 'operator new'":
<snip>
Argh, please disregard, my stupidity. Don't define functions in a
header file, only declare.... Now it works.
- Jan
JanW wrote:
Hi,
did a search for previous posts, but could still not figure out what
I'm doing wrong in my code.
Due to some DMA hardware requirements (IBM Cell processor) I'm
attempting to overload new, new[], delete and delete[] with calls to
memalign() to insure that all objects and data is aligned to 16 byte
boundaries.
For some reason I'm getting "multiple definition of 'operator new'":
If you put function definitions in headers they must be 'inline'.
Surely malloc on your target will return correctly aligned memory?
using namespace std;
NO, never ever do this in a header!
--
Ian Collins. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chris E. Yoon |
last post by:
I just want to hear people's opinions on this subject.
My application has lots and lots of short-lived objects that use
dynamic allocation/deallocation. After implementing its functionality,
I...
|
by: Woodster |
last post by:
I knoew that free is usually paired with malloc and delete is usually
paired with malloc, alloc or similar.
Can I use delete with malloc? The main reason I ask is for using the
strdup function....
|
by: Nimmi Srivastav |
last post by:
There's a rather nondescript book called "Using Borland C++" by Lee
and Mark Atkinson (Que Corporation) which presents an excellent
discussion of overloaded new and delete operators. In fact there...
|
by: some one |
last post by:
I know that C++ lets you overload functions, but how do I overload functions in C?
|
by: groleo |
last post by:
Hi list.
Simple question:
is it possible to override the global new/delete operators, without
using malloc/free?
I mean something in the ideea of the code below, which doesnt work
cause of...
|
by: Shark |
last post by:
Hi, if we need to change the behavior of operator new, it is called
overriding or overloading? My other question is, if we change the
behavior of operator new, do we use malloc to do that or we use...
|
by: Lighter |
last post by:
Big Problem! How to overload operator delete?
According to C++ standard, "A deallocation function can have more than
one parameter."(see 3.7.3.2); however, I don't know how to use an
overloaded...
|
by: mkaushik |
last post by:
Hi everyone,
Im just starting out with C++, and am curious to know how "delete
<pointer>", knows about the number of memory locations to free.
I read somewhere that delete frees up space...
|
by: richard.parker |
last post by:
Hello,
I need to overload operator new with affecting the system libraries.
Has anyone done this? I've got 2 static libraries and application
source code where the operator needs to be...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |