J
JanW
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
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