L
Lagarde Sébastien
Hello,
I write code to debug new call with following macro:
#define new (MemoryManager::Get().setOwner (__FILE__, __LINE__, _FUNCTION-),
FALSE) ? NULL : new
The setOwner allow to save the current file, line and function:
setOwner(const char *file, const u32 line, const char *func)
{
sourceFile = file;
sourceLine = line;
sourceFunc = func;
}
Then I can use this information to show some debug with an overloaded global
new opertor
void *operator new(size_t reportedSize)
{
use information
do normal new code
}
(This is the fluid studio memory manager)
This macro allow to deal with placement new.
My problem is that I need to have this debug informaiton thread safe.
So I put a critical section in Set Owner and leave it in operator new.
setOwner(const char *file, const u32 line, const char *func)
{
EnterCriticalSection()
sourceFile = file;
sourceLine = line;
sourceFunc = func;
}
void *operator new(size_t reportedSize)
{
use information
do normal new code
LeaveCriticalSection()
}
The problem is with placement new, : I don't want to debug placement new,
this is not required, but
as my macro is there I enter in SetOwner, so in the critical section but
never
leave...
So to resolve the problem I wrote my own version of placement new:
inline void* __cdecl operator new[](size_t, void* anywhere)
{
leaveCriticalSection();
return anywhere;
}
but my version of placement news seems to never been call and I block in
critical section.
I read on a web page that replacing global placement new is illegal. Is it
true ?
I try to force the usage of my placement new with some compiler specific
macro
(like define
#define __PLACEMENT_NEW_INLINE
#define __PLACEMENT_VEC_NEW_INLINE for visual 2005
before to include my own) but this seems not work.
any idea about own to force the use of my placement new ? Is it possible ?
or anybody have a better idea to debug with multithreading.
I know that i can't do an undef macro before the placement new and redo the
macro after, but as
I want to integrate external source code, I want to be able to use external
source without to have
to modify each placement new.
Thanks for your anwser.
Cheers
Sebastion Lagarde.
I write code to debug new call with following macro:
#define new (MemoryManager::Get().setOwner (__FILE__, __LINE__, _FUNCTION-),
FALSE) ? NULL : new
The setOwner allow to save the current file, line and function:
setOwner(const char *file, const u32 line, const char *func)
{
sourceFile = file;
sourceLine = line;
sourceFunc = func;
}
Then I can use this information to show some debug with an overloaded global
new opertor
void *operator new(size_t reportedSize)
{
use information
do normal new code
}
(This is the fluid studio memory manager)
This macro allow to deal with placement new.
My problem is that I need to have this debug informaiton thread safe.
So I put a critical section in Set Owner and leave it in operator new.
setOwner(const char *file, const u32 line, const char *func)
{
EnterCriticalSection()
sourceFile = file;
sourceLine = line;
sourceFunc = func;
}
void *operator new(size_t reportedSize)
{
use information
do normal new code
LeaveCriticalSection()
}
The problem is with placement new, : I don't want to debug placement new,
this is not required, but
as my macro is there I enter in SetOwner, so in the critical section but
never
leave...
So to resolve the problem I wrote my own version of placement new:
inline void* __cdecl operator new[](size_t, void* anywhere)
{
leaveCriticalSection();
return anywhere;
}
but my version of placement news seems to never been call and I block in
critical section.
I read on a web page that replacing global placement new is illegal. Is it
true ?
I try to force the usage of my placement new with some compiler specific
macro
(like define
#define __PLACEMENT_NEW_INLINE
#define __PLACEMENT_VEC_NEW_INLINE for visual 2005
before to include my own) but this seems not work.
any idea about own to force the use of my placement new ? Is it possible ?
or anybody have a better idea to debug with multithreading.
I know that i can't do an undef macro before the placement new and redo the
macro after, but as
I want to integrate external source code, I want to be able to use external
source without to have
to modify each placement new.
Thanks for your anwser.
Cheers
Sebastion Lagarde.