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 8856
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: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |