Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Overloading global new[] array operator in visual c++ 6.0

Reply
Thread Tools

Overloading global new[] array operator in visual c++ 6.0

 
 
Tim Milstead
Guest
Posts: n/a
 
      04-20-2004
(CODE AT END OF POST)

I have got some code for finding memory leaks that works well with:

new()

and needs to be extended to work with

new[]

I have to use visual C++ 6.0 to compile the project. I know that <=5.0
did not support new[] overloading but I don't know about 6.0+. Perhaps
I am just doing something bad c++ wise:

When I add/uncomment my new[] code the compiler produces the following
error:

C:\PROGRA~1\MICROS~3\VC98\INCLUDE\xlocale(21 : error C2660: 'new[]'
: function does not take 1 par
ameters
C:\PROGRA~1\MICROS~3\VC98\INCLUDE\xlocnum(53) : see reference
to function template instantia
tion 'char *__cdecl std::_Maklocstr(const char *,char *)' being
compiled
C:\PROGRA~1\MICROS~3\VC98\INCLUDE\xlocale(21 : error C2660: 'new[]'
: function does not take 1 par
ameters
C:\PROGRA~1\MICROS~3\VC98\INCLUDE\xlocnum(54) : see reference
to function template instantia
tion 'unsigned short *__cdecl std::_Maklocstr(const char *,unsigned
short *)' being compiled
NMAKE : fatal error U1077: 'cl.exe' : return code '0x2'
Stop.

The offending line in xlocale:

_E *_X = new _E[_L];

The offending code in xlocnum:

_Gr = _MAKLOCSTR(char, _P->grouping);
_Nf = _MAKLOCSTR(_E, _Lobj._Getfalse());

My header file:

#ifndef MEMORY_LEAK_FINDER_H
#define MEMORY_LEAK_FINDER_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <list>
#include <iostream.h>
//using namespace std;

// Tracing Utility
typedef unsigned long DWORD;

typedef struct {
DWORD address;
DWORD size;
char fileName[64];
DWORD lineNumber;
} ALLOCATED_INFO;

typedef std::list<ALLOCATED_INFO*> AllocatedList;

void addTrace(DWORD addr, DWORD asize, const char *fname, DWORD
lnum);
void removeTrace(DWORD addr);
extern AllocatedList *allocatedList;
void Dump();

//void * __cdecl operator new(size_t size,const char *fileName, int
lineNumber);
//void __cdecl operator delete(void *p,const char *fileName, int
lineNumber);
//void __cdecl operator delete(void *p);

inline void * operator new(size_t size,const char *fileName, int
lineNumber) {
void *ptr = (void *)malloc(size);
addTrace((DWORD)ptr, size, fileName, lineNumber);
return(ptr);
};

/*void * operator new[](size_t size,const char *fileName, int
lineNumber) {
void *ptr = (void *)malloc(size);
addTrace((DWORD)ptr, size, fileName, lineNumber);
return(ptr);
};*/

inline void operator delete(void *p,const char *fileName, int
lineNumber) {
removeTrace((DWORD)p);
free(p);
};

/*void operator delete[](void *p,const char *fileName, int
lineNumber) {
removeTrace((DWORD)p);
free(p);
}; */

inline void operator delete(void *p) {
removeTrace((DWORD)p);
free(p);
};

/*void operator delete[](void *p) {
removeTrace((DWORD)p);
free(p);
}; */


#ifdef _DEBUG
#define debugnew new(__FILE__, __LINE__)
#else
#define debugnew new
#endif



#endif
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is overloading operator. (member operator) forbidden? dascandy@gmail.com C++ 11 05-16-2007 07:54 PM
overloading global dereference operator? TuxC0d3 C++ 6 12-06-2005 12:12 AM
overloading the global operator new Zachary Turner C++ 1 12-11-2004 03:52 AM
Operator overloading on "default" operator John Smith C++ 2 10-06-2004 10:22 AM
overloading operator<< as global friend funcion Robert Wierschke C++ 3 08-03-2004 04:59 AM



Advertisments