TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MATHIEU BOUCHARD
from: DIMITRI SMITS
date: 1997-09-10 14:53:00
subject: Overloading NEW & DELETE: Help! :_(

 >  JA>   I suposse that the best approach to acomplish this is overloading 
the
 >  JA> operators new and delete. But I have a problem here: I cannot call 
he
 >  JA> "global" default new from inside my overloaded new, even using the
 > scope
 >  JA> (::) operator; every attempt to call the original new results in a
 >  JA> annoying
 >  JA> recursive call to may own overloaded new, so I can't actually 
llocate
 >  JA> memory using this approach. On the other hand, if I use malloc, the
 >  JA> program
 >  JA> crashes. I am using DJGPP 2.1 (GCC 2.7.0, I think).
 > i don't know about DJGPP, but with my compiler, there
 > is a  file
 > that includes the declarations for modifying the
 > global default new.
 > you could hook that thing: keep the old funcptr; check
 > the sizeof of
 > your object and then pass control to the old func.
if you are referring to Watcom C++ (10.6), yes, it does have
functions in new.h that 'set a new handler':
typedef int (*PFU) (unsigned);
typedef void (*PFV) (void);
typedef int (*_PNH) (unsigned);
(remind you, NOWHERE that I've found is a *_PNH used!)
after the typical formal new function descriptions 'void *operator ...'
and ofcourse the accompanying delete descriptions, I see only
2 functions:
   PVF set_new_handler( PFV );
   PFU _set_new_handler( PFU );
what those last 2 functions do (as I found out via wd) is set a value in
a tread_info_block (of which the structure is unknown to me), via
2 movs (inline). It returns the old pointer, and then replaces
it with the new function pointer.
the infoblock is called _wint_thread_data, and they are placed
at offset 0x18 and 0x1C in this block respectively.
When I check on what it is used for, I see that it does NOT
overload the new function (or the underlying malloc() of any
kind, but it is an errorhandler that you must install.
They are called when 'new' fails to find enough free memory
...
Unless you have more info on circumvening this, and can tell
me how you can hook new's and delete's internal functioncall.
I would much appreciate this, if it was true.
btw, one interesting note however is that in the .IHP file
(CLIB.IHP I believe), Watcom always gives a specification class
on whether this function is from any standard. The classification
these functions have are ... you guessed it: 'Watcom'
Greetz,
Da Gongo
--- FMail 1.02
---------------
* Origin: Hiroshima '45, Tsjernobil '86, Windows '95 (2:292/8013.12)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.